您正在获取中文文本,因为您正在从词汇表中寻找与中文文本相对应的特定范围的单词[5000:5020]
。此外,bert -base-multilingual-cased
还接受过 104 种语言的培训。
如果你想进一步验证你的代码,你可以使用这个:
tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-cased')
text = "La Banque Nationale du Canada fête cette année le 110e anniversaire de son bureau de Paris."
marked_text = "[CLS] " + text + " [SEP]"
tokenized_text = tokenizer.tokenize(marked_text)
这与您的代码相同,然后是:
token_no=[]
for token in tokenized_text:
#print(tokenizer.vocab[token]) ### you can use this to check the corresponding index of the token
token_no.append(tokenizer.vocab[token])
### The below code obtains the tokens from the index, which is similar to what you were trying, but on the correct range.
new_token_list=[]
for i in token_no:
new_token_list.append(list(tokenizer.vocab.keys())[i])
#print(new_token_list); ### you can use it if you want to check back the tokens.