私は、huggingface トランスフォーマー ライブラリを使用して、フランス語の質問応答モデルに取り組んでいます。RoBERTaに非常に似ていますが、フランス語に適応した事前トレーニング済みのCamemBERTモデルを使用しています。
現在、トランスフォーマー ライブラリの 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の回答候補を挙げたいと思います。誰もそれを行う方法を知っていますか?