我正在解码bert令牌处理器中的令牌,它将UNK作为欧元符号。但是我尝试在##€文件中添加vocab.txt令牌。但它并没有反映在预测结果和以前一样,它又给了UNK。请让我知道,为了解决这个问题,我需要微调的模型,以再次反映预测的变化。直到现在,我一直在避免微调,因为它需要超过10个小时。提前感谢
发布于 2021-05-12 22:05:09
使用令牌程序的令牌函数来避免未知令牌:
from transformers import BertTokenizer
t = BertTokenizer.from_pretrained('bert-base-uncased')
print(t.tokenize("This is an example with an emoji ."))
t.add_tokens([''])
print(t.tokenize("This is an example with an emoji ."))输出:
['this', 'is', 'an', 'example', 'with', 'an', 'em', '##oj', '##i', '[UNK]', '.']
['this', 'is', 'an', 'example', 'with', 'an', 'em', '##oj', '##i', '', '.']请记住,您还需要调整模型的大小,以便使用嵌入将其引入到新令牌中。
model.resize_token_embeddings(len(t))https://stackoverflow.com/questions/67356666
复制相似问题