【发布时间】:2020-10-16 20:07:35
【问题描述】:
我正在使用 huggingface 转换器库开发法语问答模型。我使用的是预训练的 CamemBERT 模型,它与 RoBERTa 非常相似,但适用于法语。
目前,我可以使用转换器库中的 QuestionAnsweringPipeline 为我自己的文本中的问题找到最佳答案候选者。
这是我的代码的摘录。
QA_model = "illuin/camembert-large-fquad"
CamTokQA = CamembertTokenizer.from_pretrained(QA_model)
CamQA = CamembertForQuestionAnswering.from_pretrained(QA_model)
device_pipeline = 0 if torch.cuda.is_available() else -1
q_a_pipeline = QuestionAnsweringPipeline(model=CamQA,
tokenizer=CamTokQA,
device=device_pipeline)
ctx = open("text/Sample.txt", "r").read()
question = 'Quel est la taille de la personne ?'
res = q_a_pipeline({'question': question, 'context': ctx})
print(res)
我目前得到这个:{'score': 0.9630325870663725, 'start': 2421, 'end': 2424, 'answer': '{21'} ,这是错误的。
因此,我想获得 5 个最佳候选人作为答案。有谁知道如何做到这一点?
【问题讨论】:
标签: nlp huggingface-transformers bert-language-model question-answering