Q&Aパイプラインの構築
前の演習では、PyPDFを使って複数ページのドキュメントからテキストを抽出し、1 つの文字列にまとめました。
今度は、Hugging Faceを使って質問応答パイプラインを構築し、ドキュメントから特定の回答を取得しましょう。
pipelineモジュールとdocument_textはあらかじめ読み込まれています。
この演習はコースの一部です
Hugging Faceを使いこなす
演習の手順
- 適切なタスクとモデルを指定して、質問応答パイプラインを初期化してください。
- 質問と
document_textをパイプラインに渡してください。 - 結果を出力して、回答を確認してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Load the question-answering pipeline
qa_pipeline = pipeline(task="____", model="distilbert-base-cased-distilled-squad")
question = "What is the notice period for resignation?"
# Get the answer from the QA pipeline
result = qa_pipeline(question=____, context=____)
# Print the answer
print(f"Answer: {result['____']}")