Upgrade to Pro — share decks privately, control downloads, hide ads and more …

citation fuzzy matchで学ぶstructured outputs

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

citation fuzzy matchで学ぶstructured outputs

Avatar for Atsushi Shimizu

Atsushi Shimizu

November 29, 2024
Tweet

More Decks by Atsushi Shimizu

Other Decks in Technology

Transcript

  1. 2 清水 厚志(Atsushi Shimizu) 株式会社HBA ICTソリューション本部 テクニカルエキスパート 2005年入社(20年目)/ 45歳、3人兄弟の父親 好きなこと

    • 検索技術とAI コミュニティ歴 • Elasticsearch勉強会(2023/04~) • JAWS-UG(2023/09~) • ChatGPT Community(JP) など 発表は個人の見解に基づくものであり、 所属組織を代表するものではありません。 @shimizuxa 自己紹介 今月から、LangChainを 使うPRJへ参画できた
  2. 3 citation fuzzy match の概要 【概要】 • Open AI の

    function calling を利用した仕組みで、質問と参考文書を与え、LLMより得た回答を 分割し、参考文書の出典とセットで構造化する。 https://python.langchain.com/api_reference/langchain/chains/langchain.chains.openai_functions.citation_fuzzy_match.create_citation_fuzzy_match_runnable.html 実行結果の例
  3. 5 citation fuzzy match の概要 実行結果の構造 https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/chains/openai_functions/citation_fuzzy_match.py QuestionAnswer - question:

    元の質問 - answer: FactWithEvicenceのリスト FactWithEvicence - fact: 回答 - substring_quote: 出典のリスト Pythonインスタンスが返ってくる
  4. 7 citation fuzzy matchを使えるモデル Amazon Bedrockで、OpenAI以外のモデルで動くか確認してみた Model name 結果 Claude3.5

    Sonnet anthropic.claude-3-5-sonnet-20241022-v2:0 ◦ Claude3.5 Haiku anthropic.claude-3-5-haiku-20241022-v1:0 ◦ Llama3.1 8B meta.llama3-1-8b-instruct-v1:0 × Llama3.1 70B meta.llama3-1-70b-instruct-v1:0 × Llama3.1 405B meta.llama3-1-405b-instruct-v1:0 × Command R cohere.command-r-v1:0 × Command R+ cohere.command-r-plus-v1:0 × Mistral Large mistral.mistral-large-2402-v1:0 × Mistral Small mistral.mistral-small-2402-v1:0 × Tool use(=function calling)対応の モデルからピックアップ ChatBedrock.with_structured_output モデル名に「claude-3」を 含まない場合はエラー Claude系は 正常動作した!
  5. 8 Test Run with Amazon Bedrock 実行結果(Claude3.5 Sonnet) [llm/end] [chain:RunnableSequence

    > llm:ChatBedrock] [3.60s] Exiting LLM run with output: { "generations": [ [ { "text": "", "generation_info": null, "type": "ChatGeneration", "message": { "lc": 1, "type": "constructor", "id": [ "langchain", "schema", "messages", "AIMessage" ], "kwargs": { "content": "", "additional_kwargs": { "usage": { "prompt_tokens": 790, "completion_tokens": 146, "total_tokens": 936 }, "stop_reason": "tool_use", "model_id": "anthropic.claude-3-5-sonnet-20241022-v2:0" }, "response_metadata": { "usage": { "prompt_tokens": 790, "completion_tokens": 146, "total_tokens": 936 }, "stop_reason": "tool_use", "model_id": "anthropic.claude-3-5-sonnet-20241022-v2:0" }, "type": "ai", "id": "run-af4752c3-92f8-44e7-a0b3-448d21bb139a-0", "tool_calls": [ { "name": "QuestionAnswer", "args": { "question": "今の日本の総理大臣は、何代目?", "answer": [ { "fact": "現在の日本の総理大臣は第101代の岸田文雄である。", "substring_quote": [ "第101代岸田文雄(在任: 2021年〈令和3年〉11月10日 - )" ] } ] }, "id": "toolu_bdrk_01NRBB4L9nYCXkrkfJiCGGE6", "type": "tool_call" } ], "usage_metadata": { "input_tokens": 790, "output_tokens": 146, "total_tokens": 936 }, "invalid_tool_calls": [] } } } ] ], "llm_output": { "usage": { "prompt_tokens": 790, "completion_tokens": 146, "total_tokens": 936 }, "stop_reason": "tool_use", "model_id": "anthropic.claude-3-5-sonnet-20241022-v2:0" }, "run": null, "type": "LLMResult" } 構造化結果がいい感じ Toolを呼ぶ判断結果 となっている