質問応答

Pythonで学ぶ自然言語処理(NLP)

Fouad Trad

Machine Learning Engineer

抽出型QA

  • 回答は本文から直接抜き出します

  コンテキスト「図書館は平日午後6時に閉館します」を示す画像

抽出型の回答「午後6時」を示す画像

生成型QA

  • モデルが自然な回答を生成します

  質問「平日、図書館はいつ閉館しますか?」を示す画像

生成型の回答「閉館は午後6時です」を示す画像

Pythonで学ぶ自然言語処理(NLP)

抽出型QA

  • 活用例:
    • 検索エンジン
    • 文書検索システム
    • リーディングコンプリヘンションアプリ
  • 精度が高く、誤りが少ない

extractive_photo.png

生成型QA

  • 活用例:
    • 会話エージェント
    • バーチャルアシスタント
    • カスタマーサポートボット
  • 誤りが入りやすい

abstractive_image.png

Pythonで学ぶ自然言語処理(NLP)

抽出型QA

from transformers import pipeline

qa_pipeline = pipeline(task="question-answering", model="distilbert/distilbert-base-cased-distilled-squad")
context = """The Amazon rainforest is the largest tropical rainforest in the world, covering parts of Brazil, Peru, and Colombia."""
question = "Which countries does the Amazon rainforest cover?"
qa_answer = qa_pipeline(question=question, context=context) print(qa_answer)
{'score': 0.9242347478866577,

'start': 90, 'end': 116,
'answer': 'Brazil, Peru, and Colombia'}
Pythonで学ぶ自然言語処理(NLP)

生成型QA

from transformers import pipeline
qa_pipeline = pipeline(task="text2text-generation",
                       model="fangyuan/hotpotqa_abstractive")

context = """The Amazon rainforest is the largest tropical rainforest in the world, covering parts of Brazil, Peru, and Colombia.""" question = "Which countries does the Amazon rainforest cover?"
input_text = f"question: {question} context: {context}"
result = qa_pipeline(input_text)
print(result)
[{'generated_text': 'The Amazon rainforest covers parts of Brazil, Peru, and Colombia.'}]
Pythonで学ぶ自然言語処理(NLP)

練習しましょう!

Pythonで学ぶ自然言語処理(NLP)

Preparing Video For Download...