【发布时间】:2021-12-31 10:47:47
【问题描述】:
为 Masked Language Task 使用 huggingface 转换器我预计预测将返回相同的输入字符串以及掩码的标记:
from transformers import BertConfig, BertTokenizer, BertForMaskedLM
model1 = BertForMaskedLM.from_pretrained("bert-base-uncased")
tokenizer1 = BertTokenizer.from_pretrained("bert-base-uncased")
# Read the rest of this [MASK] to understand things in more detail
text = ["Read the rest of this [MASK] to understand things in more detail"]
encoding1 = tokenizer1(text, return_tensors="pt")
# forward pass
outputs1 = model1(**encoding1)
outputs1.logits.argmax(-1)
输出是:
tensor([[1012, 3191, 1996, 2717, 1997, 2023, 2338, 2000, 3305, 2477, 1999, 2062,
1012, 1012]])
但是当我解码输出时,我没有找到最后一个输入标记 detail:
tokenizer1.convert_ids_to_tokens([1012, 3191, 1996, 2717, 1997, 2023, 2338, 2000, 3305, 2477, 1999, 2062, 1012, 1012])
['.',
'read',
'the',
'rest',
'of',
'this',
'book',
'to',
'understand',
'things',
'in',
'more',
'.',
'.']
也许我使用的模型不正确?还有其他原因吗?
【问题讨论】:
标签: python pandas huggingface-transformers