模型:
valhalla/t5-base-qa-qg-hl
这是一个为问题回答和答案感知问题生成任务训练的多任务模型。
对于问题生成,答案部分在文本中用特殊的高亮标记(<hl>)突出显示,并以“generate question:”为前缀。对于QA,输入的处理方式如下:question: question_text context: context_text </s>
您可以使用推理API与模型进行交互。以下是如何使用它的示例
对于QG
generate question: <hl> 42 <hl>是生命、宇宙和一切的答案。 </s>
对于QA
question: What is 42 context: 42是生命、宇宙和一切的答案。 </s>
有关更多详情,请参阅 this 的repo。
您需要克隆 repo 。
from pipelines import pipeline
nlp = pipeline("multitask-qa-qg", model="valhalla/t5-base-qa-qg-hl")
# to generate questions simply pass the text
nlp("42 is the answer to life, the universe and everything.")
=> [{'answer': '42', 'question': 'What is the answer to life, the universe and everything?'}]
# for qa pass a dict with "question" and "context"
nlp({
"question": "What is 42 ?",
"context": "42 is the answer to life, the universe and everything."
})
=> 'the answer to life, the universe and everything'