pal
1.0.0
紙質PAL的存儲庫:程序輔助語言模型。
在PAL中,大型語言模型通過生成文本和代碼的推理鏈來解決涉及復雜算術和程序任務的推理問題。在我們的情況下,這將代碼執行到程序運行時是Python解釋器。在我們的論文中,我們使用一些彈藥提示方法實施了PAL。

該倉庫提供了PAL的互動實現。
[2023年3月]我們增加了對ChatGpt API的支持(例如,GPT-3.5-Turbo)。我們期望PAL在Codex API關閉時會順利過渡。查看Beta腳本scripts/gsm_chatgpt.py用於數學推理。
[2023年1月]我們發布了GSM-Hard,這是我們創建的GSM8K的更難版本。在擁抱面上也可以避免?
import datasets
gsm_hard = datasets . load_dataset ( "reasoning-machines/gsm-hard" )克隆此倉庫,並與pip安裝。
git clone https://github.com/luyug/pal
pip install -e ./pal
在運行腳本之前,設置OpenAI鍵, export OPENAI_API_KEY='sk-...'
pal軟件包的核心組件是接口類。具體而言, ProgramInterface連接LLM後端,Python後端和用戶提示。
import pal
from pal.prompt import math_prompts
interface = pal.interface.ProgramInterface(
model='code-davinci-002',
stop='nnn', # stop generation str for Codex API
get_answer_expr='solution()' # python expression evaluated after generated code to obtain answer
)
question = 'xxxxx'
prompt = math_prompts.MATH_PROMPT.format(question=question)
answer = interface.run(prompt)
在這裡, interface的run方法將使用OpenAI API運行生成,運行生成的摘要,然後評估get_answer_expr (shere solution() )以獲得最終答案。
用戶應根據提示設置get_answer_expr 。
我們在scripts/文件夾中提供簡單的推理循環。
mkdir eval_results
python scripts/{colored_objects|gsm|date_understanding|penguin}_eval.py
我們有一個用於數學推理的ChatGpt專用腳本的Beta版本。
python scripts/gsm_chatgpt.py
對於運行批量推理,我們使用了通用提示庫提示,並建議它在工作中使用的所有任務上運行COT劣等。



有關結果的完整詳細信息,請參見論文。
@article{gao2022pal,
title={PAL: Program-aided Language Models},
author={Gao, Luyu and Madaan, Aman and Zhou, Shuyan and Alon, Uri and Liu, Pengfei and Yang, Yiming and Callan, Jamie and Neubig, Graham},
journal={arXiv preprint arXiv:2211.10435},
year={2022}
}