我正在尝试使用BERT将非英语文本翻译成英语。到现在为止,我正在使用的代码如下-
from pytorch_pretrained_bert.file_utils import
PYTORCH_PRETRAINED_BERT_CACHE, WEIGHTS_NAME, CONFIG_NAME
from pytorch_pretrained_bert.modeling import BertForSequenceClassification,
BertConfig
from pytorch_pretrained_bert.tokenization import BertTokenizer
from pytorch_pretrained_bert.optimization import BertAdam,
WarmupLinearSchedule
tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-uncased')
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])
token_no.append(tokenizer.vocab[token])
# The below code obtains the tokens from the index
new_token_list=[]
for i in token_no:
new_token_list.append(list(tokenizer.vocab.keys())[i])
print(new_token_list);
在此之后,我对如何获取文本的英文翻译感到困惑?我走对了吗?