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}
}