PAL: Program-aided Language Models

PAL: Program-aided Language Models

ArXiv:https://arxiv.org/pdf/2211.10435

GitHub:https://reasonwithpal.com/

一、动机

  • 大模型与Chain-of-Thought可以很好地将一些复杂的问题分解为若干个子问题并进行逐步推理;
  • 但是对于一些较为复杂的数学运算,活着涉及到交大的数字符号运算时,即便大模型对任务的规划和分解思考是正确的,但是依然会存在计算错误,这些错误通常大模型很难很好地解决;
  • 因此,本文思考将一些复杂的推理任务先用大模型进行分解,其次让大模型生成python代码并基于解释器来实现计算。通过引入代码,可以弥补由于计算错误所带来的问题。

This bridges an important gap in chain-of- thought-like methods, where reasoning chains can be correct but produce an incorrect answer.

二、方法

本文提出Program-Aided Language Model(PAL)。

相比于Chain-of-thought,每一个exemplar中包含一个推理路径,这个推理路径时融合了自然语言和python代码。且最终只提供完整的变成代码,不提供最终答案。大模型在该prompt的引导下对目标测试样本进行推理和代码生成,最终借助python解释器获得最终答案。

下图展示了一个同时含有自然语言和python代码的推理路径:

PAL方法与CoT的对比图如下所示:

Exemplar的构建

对于评测数据集中,如果现有的工作如果已经提供了exemplar,则直接使用,否则则随机采样3~6个标注样本作为exemplar。

推理路径中的代码函数名称也要与原始变量名保持一致,采用下划线分割的形式定义。

For example, a variable that describes the number of apples in the basket should have a name such as num apples in basket. This keeps the generated code linked to the entities in the question.

三、实验

数据集:

  • 数学运算:GSM8K、SVAMP、ASDIV、MAWPS;
  • 符号推理:BBH-Hard
  • 算法推理:BBH-Hard

GSM8K-Hard:

作者通过启发式更改数字的方式构建了一个新的数据集,并基于这个数据发现50%的情况下大模型虽然给出正确的推理思路但是由于交大的数字计算存在错误导致最终预测错误。

符号推理的prompt样例:

数学运算实验结果:

四、实现

Prompt

针对数学运算、符号推理、算法运算三种类型的任务分别设计了带有编程语言和自然语言的prompt。

python 复制代码
MATH_CHAT_BETA_PROMPT = '''
Let's use python to solve math problems. Here are three examples how to do it,
Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?

def solution():

"""Olivia has $23. She bought five bagels for $3 each. How much money does she have left?"""

money_initial = 23

bagels = 5

bagel_cost = 3

money_spent = bagels * bagel_cost

money_left = money_initial - money_spent

result = money_left

return result

Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?

def solution():

"""Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?"""

golf_balls_initial = 58

golf_balls_lost_tuesday = 23

golf_balls_lost_wednesday = 2

golf_balls_left = golf_balls_initial - golf_balls_lost_tuesday - golf_balls_lost_wednesday

result = golf_balls_left

return result

Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?

def solution():

"""There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?"""

computers_initial = 9

computers_per_day = 5

num_days = 4 # 4 days between monday and thursday

computers_added = computers_per_day * num_days

computers_total = computers_initial + computers_added

result = computers_total

return result

How about this question?
Q: {question}
'''.strip()
相关推荐
埃菲尔铁塔_CV算法6 分钟前
人工智能图像算法:开启视觉新时代的钥匙
人工智能·算法
EasyCVR6 分钟前
EHOME视频平台EasyCVR视频融合平台使用OBS进行RTMP推流,WebRTC播放出现抖动、卡顿如何解决?
人工智能·算法·ffmpeg·音视频·webrtc·监控视频接入
打羽毛球吗️13 分钟前
机器学习中的两种主要思路:数据驱动与模型驱动
人工智能·机器学习
光芒再现dev16 分钟前
已解决,部署GPTSoVITS报错‘AsyncRequest‘ object has no attribute ‘_json_response_data‘
运维·python·gpt·语言模型·自然语言处理
好喜欢吃红柚子29 分钟前
万字长文解读空间、通道注意力机制机制和超详细代码逐行分析(SE,CBAM,SGE,CA,ECA,TA)
人工智能·pytorch·python·计算机视觉·cnn
小馒头学python34 分钟前
机器学习是什么?AIGC又是什么?机器学习与AIGC未来科技的双引擎
人工智能·python·机器学习
神奇夜光杯43 分钟前
Python酷库之旅-第三方库Pandas(202)
开发语言·人工智能·python·excel·pandas·标准库及第三方库·学习与成长
正义的彬彬侠1 小时前
《XGBoost算法的原理推导》12-14决策树复杂度的正则化项 公式解析
人工智能·决策树·机器学习·集成学习·boosting·xgboost
Debroon1 小时前
RuleAlign 规则对齐框架:将医生的诊断规则形式化并注入模型,无需额外人工标注的自动对齐方法
人工智能
羊小猪~~1 小时前
神经网络基础--什么是正向传播??什么是方向传播??
人工智能·pytorch·python·深度学习·神经网络·算法·机器学习