紙上的代碼“變色龍:具有大語言模型的插件構圖推理”。
?如果您有任何疑問或建議,請隨時告訴我們。您可以使用電子郵件地址[email protected]直接發送電子郵件至lu,在Twitter上發表評論,或在此存儲庫上發布問題。
[項目頁面] [Paper] [Twitter] [LinkedIn] [YouTube] [幻燈片]
變色龍的暫定徽標。
Chameleon是一種插件的構圖推理框架,可通過各種類型的工具增強LLMS。 Chameleon合成了編寫各種工具的程序,包括LLM型號,現成的視覺模型,Web搜索引擎,Python功能以及針對用戶興趣的基於規則的模塊。 Chameleon建立在LLM之上,作為自然語言規劃師,它滲透了適當的工具序列,以創建和執行以產生最終響應。

我們展示了變色龍對兩個任務的適應性和有效性:ScienceQA和TABMWP。值得注意的是,具有GPT-4的變色龍在ScienceQA上的精度達到了86.54%,在最佳發表的幾桿模型上顯著提高了11.37%; Chameleon使用GPT-4作為基礎LLM,比最先進的模型增長了17.0%,導致TABMWP的總體準確性為98.78%。進一步的研究表明,與其他LLM相比,使用GPT-4作為計劃者表現出更加一致,更合理的工具選擇,並能夠推斷出潛在的限制。
有關更多詳細信息,您可以在此處找到我們的項目頁面和我們的論文。
我們要對Worldofai表示非常感謝,以在YouTube上進行介紹和介紹我們的作品!
安裝所有必需的python依賴項(由pipreqs生成):
python==3.8.10
huggingface-hub
numpy==1.23.2
openai==0.23.0
pandas==1.4.3
transformers==4.21.1
requests==2.28.1
安裝所有必需的python依賴項(如果您之前設置了依賴項,並且不需要嚴格要求版本,則可以跳過此步驟):
pip install -r requirements.txt
從:https://platform.openai.com/account/api-keys獲取OpenAi API密鑰。
要使用Chameleon的OpenAI API密鑰,您需要設置計費(又稱付費帳戶)。
您可以在https://platform.openai.com/account/billing/overview上設置付費帳戶。
從:https://www.microsoft.com/en-us/bing/apis/bing-web-search-api獲取您的Bing搜索API密鑰。
Bing搜索API密鑰是可選的。無法設置此鍵將導致ScienceQA任務的略有性能下降。
我們的模塊清單中的不同類型的工具:

科學QA和TABMWP上使用的工具。綠色中突出顯示了兩個任務中的可重複使用的工具:

科學問題回答(ScienceQA)是一種多模式的提問基準,涵蓋了各種環境中廣泛的科學主題。 ScienceQA數據集在data/scienceqa中提供。有關更多詳細信息,您可以探索數據集並查看探索頁面並可視化頁面。
對於當前版本, Image Captioner和Text Detector的結果分別存儲在data/scienceqa/captions.json和data/scienceqa/ocrs.json中。現場呼叫這兩個模塊即將到來!
運行變色龍(GPT-4):
cd run_scienceqa
python run.py
--model chameleon
--label chameleon_gpt4
--policy_engine gpt-4
--kr_engine gpt-4
--qg_engine gpt-4
--sg_engine gpt-4
--test_split test
--test_number -1它將生成預測並保存結果results/scienceqa/chameleon_gpt4_test.json , results/scienceqa/chameleon_gpt4_test_cache.json results/scienceqa/chameleon_gpt4_test_cache.jsonl
我們可以通過運行來平均和在不同的問題類中獲得準確度指標:
python evaluate.py
--data_file ../data/scienceqa/problems.json
--result_root ../results/scienceqa
--result_files chameleon_chatgpt_test_cache.jsonl運行變色龍(chatgpt):
python run.py
--model chameleon
--label chameleon_gpt4
--policy_engine gpt-3.5-turbo
--kr_engine gpt-3.5-turbo
--qg_engine gpt-3.5-turbo
--sg_engine gpt-3.5-turbo
--test_split test
--test_number -1我們的變色龍是COT(經營鏈)方法的廣義形式,其中生成的程序是Solution Generator和Answer Generator的序列。通過傳遞--model作為cot ,將modules設置為["solution_generator", "answer_generator"] 。
運行COT(經過深思熟慮的鏈接)GPT-4:
python run.py
--model cot
--label cot_gpt4
--sg_engine gpt-4
--test_split test
--test_number -1運行cot(經過經過經過經過經過經驗的鏈條)chatgpt:
python run.py
--model cot
--label cot_chatgpt
--sg_engine gpt-4
--test_split test
--test_number -1TABMWP數據集包含38,431個表格數學單詞問題。 TABMWP中的每個問題都與表格上下文對齊,該上下文作為圖像,半結構化文本和結構化表。 TABMWP數據集在data/tabmwp中提供。有關更多詳細信息,您可以探索數據集並查看探索頁面並可視化頁面。
運行變色龍(GPT-4):
cd run_tabmwp
python run.py
--model chameleon
--label chameleon_gpt4
--test_split test
--policy_engine gpt-4
--rl_engine gpt-4
--cl_engine gpt-4
--tv_engine gpt-4
--kr_engine gpt-4
--sg_engine gpt-4
--pg_engine gpt-4
--test_number -1
--rl_cell_threshold 18
--cl_cell_threshold 18它將生成預測並將結果保存在results/tabmwp/chameleon_gpt4_test.json , results/tabmwp/chameleon_gpt4_test_cache.jsonl ,以及results/tabmwp/chameleon_gpt4_test_cache.json 。
我們可以通過運行來平均和在不同的問題類中獲得準確度指標:
python evaluate.py
--data_file ../data/tabmwp/problems_test.json
--result_root ../results/tabmwp
--result_files chameleon_chatgpt_test_cache.jsonl運行變色龍(chatgpt):
python run.py
--model chameleon
--label chameleon_chatgpt
--test_split test
--policy_engine gpt-3.5-turbo
--rl_engine gpt-3.5-turbo
--cl_engine gpt-3.5-turbo
--tv_engine gpt-3.5-turbo
--kr_engine gpt-3.5-turbo
--sg_engine gpt-3.5-turbo
--pg_engine gpt-3.5-turbo
--test_number -1
--rl_cell_threshold 18
--cl_cell_threshold 18運行COT(經過深思熟慮的鏈接)GPT-4:
python run.py
--model cot
--label cot_gpt4
--test_split test
--sg_engine gpt-4
--test_number -1運行cot(經過經過經過經過經過經驗的鏈條)chatgpt:
python run.py
--model cot
--label cot_chatgpt
--test_split test
--sg_engine gpt-3.5-turbo
--test_number -1我們的變色龍是POT(計劃程序)方法的廣義形式,其中生成的程序是Program Generator , Program Executor和Answer Generator的順序。通過傳遞--model作為pot , modules被設置為["program_generator", "program_executor", "answer_generator"] 。
運行POT(經過深思熟慮的計劃)GPT-4:
python run.py
--model pot
--label pot_gpt4
--test_split test
--pg_engine gpt-4
--test_number -1運行POT(經過經過經過經過經驗計劃的提示)CHATGPT:
python run.py
--model pot
--label pot_chatgpt
--test_split test
--pg_engine gpt-3.5-turbo
--test_number -1
Chameleon (GPT-4)能夠通過生成組成各種工具並順序執行的程序來適應不同的輸入查詢,以獲得正確的答案。
例如,上面的查詢問:“哪種動物的皮膚適合在寒冷的地方生存?”,其中涉及與動物生存有關的科學術語。因此,計劃者決定依靠Bing搜索引擎來獲取特定於領域的知識,從而受益於可用的眾多在線資源。

在TABMWP上還觀察到我們的變色龍對各種查詢的適應性和多功能性,如上圖所示。
第一個示例涉及稅收形式的數學推理。 Chameleon (1)稱知識檢索模型回想起有助於理解此類域特異性表的基本知識,(2)以更可讀的自然語言格式描述表,(3)最終依靠程序輔助工具來執行執行精確計算。
在第二個示例中,系統生成Python代碼,該代碼與知識檢索模型提供的背景知識緊密一致。
第三個示例要求該系統在給定輸入查詢的情況下將單元格位於大的表格上下文中。 Chameleon調用行查找模型以幫助準確地定位相關行並通過LLM模型生成語言解決方案,而不是依靠基於程序的工具。
對於微型型號和幾乎沒有射擊的促使GPT-4/CHATGPT的變色龍觀察到了重大改進:

為了可視化變色龍的預測,只需執行與您的特定任務相對應的jupyter筆記本: notebooks/results_viewer_[TASK].ipynb 。這將提供一種交互式和用戶友好的方式來探索該模型產生的結果。或者,探索我們的項目頁面以獲取更多信息和選項。
Chemeleon (Chatgpt)和Chameleon (GPT-4)的生成程序中調用的工具:ScienceQA:

在TABMWP上的Chameleon(ChatGpt)和Chameleon(GPT-4)的生成程序中調用的工具:

執行notebooks/transition_[TASK]_[Model]_Engine.ipynb可視化測試集生成的程序的模塊過渡圖。
Chameleon (GPT-4)在ScienceQA上產生的程序中模塊之間的過渡。啟動是開始符號,end是終端符號,而其他符號是非末端符號。

Chameleon (GPT-4)在TABMWPQA上生成的程序中模塊之間的過渡。啟動是開始符號,end是終端符號,而其他符號是非末端符號。

demos目錄中為基於LLM的模型創建提示。在model.py中定義每個模塊的輸入,執行和輸出。model.py中定義數據加載程序。要修改評估方法,請在main.py中更新相應的部分。極好的!我總是願意進行討論,合作,甚至只是分享虛擬咖啡。要取得聯繫,請訪問Pan Lu的主頁以獲取聯繫信息。
如果您發現變色龍對您的研究和應用程序有用,請使用此Bibtex友好地引用:
@article{lu2023chameleon,
title={Chameleon: Plug-and-Play Compositional Reasoning with Large Language Models},
author={Lu, Pan and Peng, Baolin and Cheng, Hao and Galley, Michel and Chang, Kai-Wei and Wu, Ying Nian and Zhu, Song-Chun and Gao, Jianfeng},
journal={arXiv preprint arXiv:2304.09842},
year={2023}
}