我尝试使用“pytorch pretrained BERT”模型来执行Q&A当我尝试使用它时,我意识到,每次评估示例时,输出都是随机的,因此是不正确的。我在处理这个tutorial。你知道吗
text = "[CLS] Who was Jim Henson ? [SEP] Jim Henson was a puppeteer [SEP]"
(...)
questionAnswering_model = torch.hub.load('huggingface/pytorch-pretrained-BERT', 'bertForQuestionAnswering', 'bert-base-cased')
questionAnswering_model.eval()
# Predict the start and end positions logits
with torch.no_grad():
start_logits, end_logits = questionAnswering_model(tokens_tensor, segments_tensors)
start = np.argmax(start_logits[0])
end = np.argmax(end_logits[0])
answer = tokens_tensor[start:end]
示例:
1: ['Who', 'was', 'Jim', 'He', '##nson', '?', '[SEP]', 'Jim']
2: ['##nson', 'was', 'a', 'puppet']
我是否以正确的方式使用开始和结束登录来获得答案?我能做些什么来纠正随机数?你知道吗
先谢谢你
目前没有回答
相关问题 更多 >
编程相关推荐