@@ -283,21 +283,22 @@ def __init__(self, fname_tokenizer: Path, fname_added_tokens: Optional[Path], fn
283
283
else :
284
284
tokenizer_config = {}
285
285
for key , value in tokenizer_config .items ():
286
- assert isinstance (value , dict ) or isinstance (value , str )
287
- if key not in TOKEN_NAME_TO_ID or TOKEN_NAME_TO_ID [key ] == - 1 :
286
+ if not isinstance (value , dict ) or not isinstance (value , str ):
288
287
continue
289
- self .special_tokens_map [TOKEN_NAME_TO_ID [key ]] = value ["content" ] if isinstance (value , dict ) else value
288
+ token_id = TOKEN_NAME_TO_ID .get (key , - 1 )
289
+ if token_id == - 1 :
290
+ continue
291
+ self .special_tokens_map [token_id ] = value ["content" ] if isinstance (value , dict ) else value
290
292
291
293
special_tokens : Dict [str , Any ]
292
294
if fname_special_tokens is not None :
293
295
special_tokens = json .load (open (fname_special_tokens ))
294
296
else :
295
297
special_tokens = {}
296
298
for key , value in special_tokens .items ():
297
- assert isinstance (value , dict ) or isinstance (value , str )
298
- if key not in TOKEN_NAME_TO_ID :
299
+ if not isinstance (value , dict ) or not isinstance (value , str ):
299
300
continue
300
- token_id = TOKEN_NAME_TO_ID [ key ]
301
+ token_id = TOKEN_NAME_TO_ID . get ( key , - 1 )
301
302
if token_id == - 1 or token_id in self .special_tokens_map :
302
303
continue
303
304
self .special_tokens_map [token_id ] = value ["content" ] if isinstance (value , dict ) else value
0 commit comments