Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
LangChainについてのサーベイ
Search
Melonps
June 20, 2023
Technology
230
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LangChainについてのサーベイ
2023年5月頃に流行ったLangChainについて自ら調べ、研究室内で発表しました。
Melonps
June 20, 2023
More Decks by Melonps
See All by Melonps
コーディングエージェントはTypeScriptの 型エラーをどう自己修正しているのか
melonps
4
850
Zodのデータ変換が便利すぎた。 しかし使いすぎで苦しくなっていった話
melonps
0
98
さくらのAI Engineから始める クラウドネイティブ意識
melonps
0
360
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
790
OpenTelemetryで“見えるIoT”を目指したら クラウドネイティブの奥深さに直面した
melonps
0
100
CloudSeed
melonps
0
200
Other Decks in Technology
See All in Technology
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
330
LLM Content Moderationを支える評価・改善ループの実践
suikabar
2
280
AI × アーキテクト 第1・2章|生成AIの課題とアーキテクトの素養
daidaidai
1
220
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
PRO
0
450
オントロジーって 結局なにもの? AI エージェントに「意味」を渡す知識設計の話
greenmidori
0
250
僕のハーネスを紹介します
watany
4
1.3k
データエンジニアの次の戦場は "プロセスエンジニアリング"
sansantech
PRO
1
150
AI駆動開発におけるハーネスエンジニアリングの勘所
tsukuboshi
1
350
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
170
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
150
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
170
Turning Repos into the Product Second Brain with an LLM Wiki
linedevth
0
130
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
540
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
Utilizing Notion as your number one productivity tool
mfonobong
4
620
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
740
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
370
Into the Great Unknown - MozCon
thekraken
41
2.8k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
Building AI with AI
inesmontani
PRO
1
1.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Transcript
Lang Chainの概要と使い方 第3グループ Kakehi(Melonps) 技術サーベイ 1
発表の概要 •GPTなどLLM(大規模言語モデル )を研究で使いたい人向け •こんなこともできるらしいぞ!という紹介 2 LangChainとは •LLMの機能拡張を実装するためのライブラリ •異なる種類のLLMを同じインターフェースで利用可 •結局はプロンプトに帰着
こんなこと苦手だよね!GPT •正確な情報の提供 •複雑な計算を含む質問 •多数の質問の一括処理 •アートや視覚に関する質問 3 GPTが作成した ミッキーのSVG →GPTの機能を拡張する必要あり!
どのような場合に使うのか? •最新の検索結果の内容も踏まえて返答をさせたい ◦ 検索結果に「~なのだ」を付けて返答させたい[1] •長文を踏まえて返答させたい ◦ pdfなど特殊なデータ形式から[2] ◦ 長文の要約[3] •複雑な計算問題を回答させたい[4]
[1]LangChain の Googleカスタム検索 連携を試す|npaka, https://note.com/npaka/n/nd9a4a26a8932 [2]話題の ChatGPT + LangChain で、膨大な PDF ドキュメントの内容を爆速で把握する - Qiita, https://qiita.com/hiroki_okuhata_int/items/7102bab7d96eb2574e7d [3]長文から論点を抽出して、その論点を軸に文章の要約を試みる| mah\_lab / 西見 公宏, https://note.com/mahlab/n/ndce1a18681e8 [4]LangChainの使い方 紹介編 - Qiita, https://qiita.com/kzkymn/items/a72796c89ffc696034c8#6-wolfram-alpha%E3%81%A8%E9%80%A3%E6%90%BA%E3%81%99%E3%82%8B
具体的な機能は6つ 01. Models :言語モデルやチャットモデルを組み合わせ 02. Prompt :プロンプトの管理、シリアル化 03. Indexes :PDFなどの外部データを使用
04. Chains :複数のプロンプトを入力 05. Agents :どのような手段でどういう順番で解決するか 06. Memory :ChainsやAgentsの内部状態を保持 イメージが掴みにくい方:[5] LangChainの概要と使い方|サクッと始めるプロンプトエンジニアリング【LangChain / ChatGPT】, https://zenn.dev/umi_mori/books/prompt-engineer/viewer/langchain_overview もっと詳しく見たい方:[6] https://langchain.com/features.html
目次 01. 概要 02. 実装例を見てみよう 03. 質問 6
実装例を見てみよう! 01. Models :言語モデルやチャットモデルを組み合わせ 02. Prompt :プロンプトの管理、シリアル化 03. Indexes :PDFなどの外部データを使用
04. Chains :複数のプロンプトを入力 05. Agents :どの手段でどういう順番で解決するかを決定 06. Memory :ChainsやAgentsの内部状態を保持 以降では参考文献[1]の内容を借りて説明
仕様とやりたいこと •仕様 ◦ Google検索の結果を使いたい ◦ 一人称は"ぼく"、語尾には"なのだ"をつけたい •やりたいこと ◦ AgentsにGoogle検索のアクセスを許可 ◦
→それをカスタマイズして語尾などを使用 8
必要なもの •Tools ◦ API:SerpAPI(入力はクエリ) ◦ LLMs:OpenAIのGPT-3系モデル •Agents(6種類) ◦ ツールの説明のみに基づいて使用ツールを決定 →zero-shot-react-description
• プロンプトテンプレート ◦ 「次のToolsにアクセスできるから使って◦◦に答えてね。」 ◦ 「語尾は◦◦を使用してね。それじゃあ始めて。」 • Chains ◦ 複数のプロンプトテンプレートを入力→LLMchain 9
ぼっち・ざ・ろっくの作者の 名前は? 図解 Tools テンプレ プロンプト Tools テンプレ × 2
Agents 質問 はまじあきなのだ。 回答 Chains
コードを見る(Python) 11 from langchain.agents import ZeroShotAgent, Tool, AgentExecutor, load_tools from
langchain import OpenAI, SerpAPIWrapper, LLMChain # Toolsの準備 tools = load_tools([ "google-search" ], llm=OpenAI()) # デフォルトでGPT-3のモデルを選択 # プロンプトテンプレートの準備 prefix = """次の質問にできる限り答えてください。次のツールにアクセスできます :""" suffix = """始めましょう! 最終的な答えを出すときは、一人称は "ぼく"、語尾には"なのだ"を使用してください Question: {input} {agent_scratchpad}""" prompt = ZeroShotAgent.create_prompt( tools, # Agentsがアクセスできる Toolのリスト prefix=prefix, # Tools一覧の前に付けるテンプレート suffix=suffix, # Tools一覧の後に付けるテンプレート input_variables=["input", "agent_scratchpad"] # 最終プロンプトが期待する入力変数のリスト ) # Agentsの準備 llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt) # 温度が低いほど出現率の高い単語を選択 agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools) agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True)
説明の正確さの予測 12 agent_executor.run( "ぼっち・ざ・ろっくの作者の名前は? ") > Entering new AgentExecutor chain...
Thought: この質問に答えるために、 Google Search を使う必要がある Action: Google Search Action Input: "ぼっち・ざ・ろっくの作者 " Observation: まんがタイムきらら MAXで『ぼっち・ざ・ろっく!』載せてもらってます ⑤巻発売中。アニメ 2022年10~12月放 送してました。バンド大好き!通知切ってるのでリプライ ... 『ぼっち・ざ・ろっく!』( BOCCHI THE ROCK! )は、はまじ あきによる日本の 4コマ漫画。『まんがタイムきらら MAX』(芳文社)にて、 2018年2月号から4月号までゲスト連載 ... Nov 29, 2022 ... その筆頭といえるのが、アニメが今期最大級の注目作となっている『ぼっち・ざ・ろっく』の作者、はまじあき であろう。もともとはまじは「ちゃお」で ... Feb 27,2019 ... Thought: はまじあきが『ぼっち・ざ・ろっく!』の作者であることがわかった Final Answer: はまじあきなのだ。 > Finished AgentExecutor chain. 'はまじあきなのだ。 会話の実行 実行結果
Agentがやっていること 01. llm で推論 02. 推論した結果からActionとAction Inputとして利用すべき Toolsと内容を取り出し 03. Toolsの実行
04. Toolsの結果をObservationに入力 05. OvservationからllmがThoughtを出力 06. Final Answersの出力 [7]LangChainのAgent「zero-shot-react-description」はLLMとどう連携しているのか?調べた - まったり勉強ノート , https://www.mattari-benkyo-note.com/2023/04/05/langchain_zero-shot-react-description/ [8]LangChainのAgentがどのようにToolを選択しているかを確認したメモ - INOUE-KOBO.COM, https://www.inoue-kobo.com/ai_ml/langchain-agent/
Lang Chainの概要と使い方 第3グループ kake 技術サーベイ 14
目次 01. 概要 02. 実装例を見てみよう 03. 質問 15
agent_scratchpadとは? •エージェントが仲介作業を置くことができる変数 •LLMChainのプロンプトでは必ず必要 •中間生成物というイメージ(イメージ) 16
ReActとは •論文[9]で提案されている手法 ◦ 1.次に何をすべきか?を考える ◦ 2.考えに基づいてアクションを実行し、アクションの結果を得る •入力のテキストの前にいろいろ追加で文章を付け加えて LLMに投げる 17 [9]ReAct:
Synergizing Reasoning and Acting in Language Models, Shunyu .et al, https://arxiv.org/abs/2210.03629