これは、思考のグラフの公式実装です。大規模な言語モデルで精巧な問題を解決します。
このフレームワークは、エンジンとして大規模な言語モデル(LLM)で自動的に実行される操作(GOO)のグラフとしてそれらをモデル化することにより、複雑な問題を解決することができます。
このフレームワークは、柔軟で拡張可能になるように設計されており、新しいGOTアプローチを使用して問題を解決するだけでなく、COTやTOTなどの以前のアプローチに似たGoosを実装することもできます。
このフレームワークを使用するには、Python 3.8以降の動作インストールが必要です。
次の2つのインストール方法のいずれかを実行する前に、事前にPython環境(ある場合)をアクティブにしてください。
あなたがユーザーであり、 graph_of_thoughts使用するだけの場合は、Pypiから直接インストールできます。
pip install graph_of_thoughts開発者であり、コードを変更する場合は、ソースから編集モードにインストールできます。
git clone https://github.com/spcl/graph-of-thoughts.git
cd graph-of-thoughts
pip install -e .フレームワークを使用するには、LLMにアクセスする必要があります。コントローラーREADMEの指示に従って、選択したLLMを構成してください。
次のコードスニペットは、COTのようなアプローチを使用して、32の数字のリストの並べ替えの問題を解決するためにフレームワークを使用する方法を示しています。
コードを実行する前に、セットアップガイドに従っていることを確認してください。
from examples . sorting . sorting_032 import SortingPrompter , SortingParser , utils
from graph_of_thoughts import controller , language_models , operations
# Problem input
to_be_sorted = "[0, 2, 6, 3, 8, 7, 1, 1, 6, 7, 7, 7, 7, 9, 3, 0, 1, 7, 9, 1, 3, 5, 1, 3, 6, 4, 5, 4, 7, 3, 5, 7]"
# Create the Graph of Operations
gop = operations . GraphOfOperations ()
gop . append_operation ( operations . Generate ())
gop . append_operation ( operations . Score ( scoring_function = utils . num_errors ))
gop . append_operation ( operations . GroundTruth ( utils . test_sorting ))
# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)
lm = language_models . ChatGPT ( "config.json" , model_name = "chatgpt" )
# Create the Controller
ctrl = controller . Controller (
lm ,
gop ,
SortingPrompter (),
SortingParser (),
# The following dictionary is used to configure the initial thought state
{
"original" : to_be_sorted ,
"current" : "" ,
"method" : "cot"
}
)
# Run the Controller and generate the output graph
ctrl . run ()
ctrl . output_graph ( "output_cot.json" )より洗練されたGotアプローチを実行するには、次のコードスニペットを使用できます。
from examples . sorting . sorting_032 import SortingPrompter , SortingParser , got , utils
from graph_of_thoughts import controller , language_models , operations
# Problem input
to_be_sorted = "[0, 2, 6, 3, 8, 7, 1, 1, 6, 7, 7, 7, 7, 9, 3, 0, 1, 7, 9, 1, 3, 5, 1, 3, 6, 4, 5, 4, 7, 3, 5, 7]"
# Retrieve the Graph of Operations
gop = got ()
# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)
lm = language_models . ChatGPT ( "config.json" , model_name = "chatgpt" )
# Create the Controller
ctrl = controller . Controller (
lm ,
gop ,
SortingPrompter (),
SortingParser (),
# The following dictionary is used to configure the initial thought state
{
"original" : to_be_sorted ,
"current" : "" ,
"phase" : 0 ,
"method" : "got"
}
)
# Run the Controller and generate the output graph
ctrl . run ()
ctrl . output_graph ( "output_got.json" )出力グラフoutput_cot.jsonとoutput_got.json検査することにより、2つの結果を比較できます。
最終的な思考のスコアは、ソートされたリストのエラーの数を示しています。
このペーパーでは、フレームワークとそのコンポーネントの高レベルの概要を説明します。
フレームワークをより詳細に理解するために、個々のモジュールのドキュメントを読むことができます。
特に、コントローラーと操作モジュールは、フレームワークを最大限に活用する方法を理解するために重要です。
コードがどのように機能し、どのように拡張するかを簡単に理解できるように、コードを完全に文書化するように特別な注意を払っています。
例には、ディレクトリには、ペーパーで提示されたものを含むフレームワークを使用して解決できる問題のいくつかの例が含まれています。
これは、フレームワークを使用して実際の問題を解決する方法を学ぶための素晴らしい出発点です。
それぞれの例には、 README.mdファイルが含まれており、それを実行して再生する方法についての指示があります。コードは完全に文書化されており、簡単に従うことができます。メインディレクトリからまっすぐに例を実行することもできます。結果は、それぞれのサブディレクトリに保存されることに注意してください。
たとえば、試してみてください:
python -m examples.sorting.sorting_032
python -m examples.keyword_counting.keyword_counting例ディレクトリの指示に従って、ペーパーから実験を実行できます。
ただし、結果を検査して再現するだけの場合は、Paper Directoryを使用できます。
このリポジトリが価値があると思う場合は、星を挙げてください!
質問やフィードバックがありますか? [email protected]に自由に連絡するか、問題を開いてください。
あなたの仕事でこれを使っていますか?提供された引用を使用して私たちを参照してください:
@article { besta2024got ,
title = { {Graph of Thoughts: Solving Elaborate Problems with Large Language Models} } ,
author = { Besta, Maciej and Blach, Nils and Kubicek, Ales and Gerstenberger, Robert and Gianinazzi, Lukas and Gajda, Joanna and Lehmann, Tomasz and Podstawski, Micha{l} and Niewiadomski, Hubert and Nyczyk, Piotr and Hoefler, Torsten } ,
year = 2024 ,
month = { Mar } ,
journal = { Proceedings of the AAAI Conference on Artificial Intelligence } ,
volume = 38 ,
number = 16 ,
pages = { 17682-17690 } ,
publisher = { AAAI Press } ,
doi = { 10.1609/aaai.v38i16.29720 } ,
url = { https://ojs.aaai.org/index.php/AAAI/article/view/29720 }
}