《Toolformer: Language Models Can Teach Themselves to Use Tools》论文解读

news2024/9/20 20:23:03

0. 引言

《Toolformer: Language Models Can Teach Themselves to Use Tools》 论文主要探讨了语言模型(LMs)在解决新任务时的能力和局限性,并提出了一个名为 Toolformer 的新方法。该方法通过简单 API 接口将外部工具与 LMs 相结合,实现了 LMs 在自监督学习中的自我训练。实验结果表明,Toolformer 在保留了核心的语言建模能力的基础上,能显著提高零样本下的下游任务表现,且在许多情况下甚至可以与更大规模的模型相媲美。

1. 数据处理

数据处理希望达到以下的结果:

其中,颜色框出的部分是 API 调用:工具+参数+答案。那么这些数据是如何生成的呢?论文中实际上是通过 few-shot 的方式,给出一些例子让其他大模型根据例子去生成满足这些格式的数据样本。

其中,工具和对应的 Prompts:

  • 问题回答
Your task is to add calls to a Question
Answering API to a piece of text.
The questions should help you get
information required to complete the
text. You can call the API by writing
"[QA(question)]" where "question" is the
question you want to ask. Here are some
examples of API calls:
Input: Joe Biden was born in Scranton,
Pennsylvania.
Output: Joe Biden was born in [QA("Where
was Joe Biden born?")] Scranton,
[QA("In which state is Scranton?")]
Pennsylvania.
Input: Coca-Cola, or Coke, is a
carbonated soft drink manufactured by
the Coca-Cola Company.
Output: Coca-Cola, or [QA("What other
name is Coca-Cola known by?")] Coke, is
a carbonated soft drink manufactured by
[QA("Who manufactures Coca-Cola?")] the
Coca-Cola Company.
Input: x
Output:
  • 计算器
Your task is to add calls to a
Calculator API to a piece of text.
The calls should help you get
information required to complete the
text. You can call the API by writing
"[Calculator(expression)]" where
"expression" is the expression to be
computed. Here are some examples of API
calls:
Input: The number in the next term is 18
+ 12 x 3 = 54.
Output: The number in the next term is
18 + 12 x 3 = [Calculator(18 + 12 * 3)]
54.
Input: The population is 658,893 people.
This is 11.4% of the national average of
5,763,868 people.
Output: The population is 658,893 people.
This is 11.4% of the national average of
[Calculator(658,893 / 11.4%)] 5,763,868
people.
Input: A total of 252 qualifying matches
were played, and 723 goals were scored
(an average of 2.87 per match). This is
three times less than the 2169 goals
last year.
Output: A total of 252 qualifying
matches were played, and 723 goals were
scored (an average of [Calculator(723
/ 252)] 2.87 per match). This is twenty
goals more than the [Calculator(723 -
20)] 703 goals last year.
Input: I went to Paris in 1994 and
stayed there until 2011, so in total,
it was 17 years.
Output: I went to Paris in 1994 and
stayed there until 2011, so in total, it
was [Calculator(2011 - 1994)] 17 years.
Input: From this, we have 4 * 30 minutes
= 120 minutes.
Output: From this, we have 4 * 30
minutes = [Calculator(4 * 30)] 120
minutes.
Input: x
Output:
  • 维基百科搜索
Your task is to complete a given piece
of text. You can use a Wikipedia Search
API to look up information. You can do
so by writing "[WikiSearch(term)]" where
"term" is the search term you want to
look up. Here are some examples of API
calls:
Input: The colors on the flag of Ghana
have the following meanings: red is for
the blood of martyrs, green for forests,
and gold for mineral wealth.
Output: The colors on the flag of Ghana
have the following meanings: red is for
[WikiSearch("Ghana flag red meaning")]
the blood of martyrs, green for forests,
and gold for mineral wealth.
Input: But what are the risks during
production of nanomaterials? Some nanomaterials may give rise to various
kinds of lung damage.
Output: But what are the risks
during production of nanomaterials?
[WikiSearch("nanomaterial production
risks")] Some nanomaterials may give
rise to various kinds of lung damage.
Input: Metformin is the first-line drug
for patients with type 2 diabetes and
obesity.
Output: Metformin is the first-line drug
for [WikiSearch("Metformin first-line
drug")] patients with type 2 diabetes
and obesity.
Input: x
Output:
  • 机器翻译
Your task is to complete a given piece
of text by using a Machine Translation
API.
You can do so by writing "[MT(text)]"
where text is the text to be translated
into English.
Here are some examples:
Input: He has published one book: O
homem suprimido (“The Supressed Man”)
Output: He has published one book: O
homem suprimido [MT(O homem suprimido)]
(“The Supressed Man”)
Input: In Morris de Jonge’s Jeschuah,
der klassische jüdische Mann, there is a
description of a Jewish writer
Output: In Morris de Jonge’s Jeschuah,
der klassische jüdische Mann [MT(der
klassische jüdische Mann)], there is a
description of a Jewish writer
Input: 南 京 高 淳 县 住 房 和 城 乡 建 设 局 城 市 新
区 设 计 a plane of reference Gaochun is
one of seven districts of the provincial
capital Nanjing
Output: [MT(南京高淳县住房和城乡建设局 城市新
区 设 计)] a plane of reference Gaochun is
one of seven districts of the provincial
capital Nanjing
Input: x
Output:
  • 日历
Your task is to add calls to a Calendar
API to a piece of text. The API calls
should help you get information required
to complete the text. You can call the
API by writing "[Calendar()]" Here are
some examples of API calls:
Input: Today is the first Friday of the
year.
Output: Today is the first [Calendar()]
Friday of the year.
Input: The president of the United
States is Joe Biden.
Output: The president of the United
States is [Calendar()] Joe Biden.
Input: The current day of the week is
Wednesday.
Output: The current day of the week is
[Calendar()] Wednesday.
Input: The number of days from now until
Christmas is 30.
Output: The number of days from now
until Christmas is [Calendar()] 30.
Input: The store is never open on the
weekend, so today it is closed.
Output: The store is never open on the
weekend, so today [Calendar()] it is
closed.
Input: x
Output:

2. 整体流程

API 调用表示为:
c = ( a c , i c ) c = (a_c, i_c) c=(ac,ic)
其中:

(1) c c c 表示 API 调用;

(2) a c a_c ac 是 API 的名字;

(3) i c i_c ic 是对应的输入。

根据有没有 API 输出,可以分为:
e ( c ) = < A P I > a c ( i c ) < / A P I > e(c) = < API > a_c(i_c) < / API > e(c)=<API>ac(ic)</API>
e ( c , r ) = < A P I > a c ( i c ) → r < / A P I > e(c,r) = < API > a_c(i_c) → r < / API > e(c,r)=<API>ac(ic)r</API>
其中,“<API>”,“</API>” 和 “→”是特殊的 token,用于标识中间内容是需要调用第三方工具的,实际中分别对应 “[”,、“]” 和 “->”。

2.1 API调用采样

根据前一章节的数据处理,让大模型自动生成多个 API 调用,如下:

对于模型 M M M z n + 1 z_{n+1} zn+1作为 z 1 , . . . , z n z_1,...,z_n z1,...,zn后一个序列的概率:
p M ( z n + 1 ∣ z 1 , . . . , z n ) p_M(z_{n+1}|z_1,...,z_n) pM(zn+1z1,...,zn)
那么,对于每一个 i ∈ 1 , . . . , n i\in{1,...,n} i1,...,n i i i 插入 API 调用的概率:
p i = p M ( < A P I > ∣ P ( x ) , x 1 : i − 1 ) p_i = p_M(< API > | P(\mathbf{x}),x_{1:i-1}) pi=pM(<API>P(x),x1:i1)

当设置一个概率阈值 τ \tau τ 后和采样上限 k k k 后,则可以获取插入的位置:
I = { i ∣ p i > τ s } I= \{ i|p_i > \tau_s \} I={ipi>τs}
如果满足的插入位置超过 k k k 之后,只取概率最大的前 k k k 个。

2.2 执行 API 调用

下一步执行所有 API 调用来获得相应的结果。可能涉及到调用另一个神经网络处理、执行 Python 脚本或使用检索系统在大型语料库上执行搜索。

2.3 过滤 API 调用结果

首先定义权重交叉熵 loss:
L i ( z ) = − ∑ j = i n ω j − i ⋅ l o g p M ( x j ∣ z , x 1 : j − 1 ) L_i(\mathbf{z})=-\sum_{j=i}^n\omega_{j-i} \cdot logp_M(x_j|\mathbf{z},x_{1:j-1}) Li(z)=j=inωjilogpM(xjz,x1:j1)
现考虑两种 loss:
L i + = L i ( e ( c i , r i ) ) L_i^+=L_i(e(c_i,r_i)) Li+=Li(e(ci,ri))
L i − = m i n ( L i ( ϵ ) , L i ( e ( c i , ϵ ) ) ) L_i^-=min(L_i(\epsilon),L_i(e(c_i,\epsilon))) Li=min(Li(ϵ),Li(e(ci,ϵ)))
其中:

(1) ϵ \epsilon ϵ 表示空序列;

(2) L i ( ϵ ) L_i(\epsilon) Li(ϵ) 表示没有插入 API 调用;

(3) L i ( e ( c i , ϵ ) ) L_i(e(c_i,\epsilon)) Li(e(ci,ϵ)) 表示 API 调用输出为空;

(4) L i ( e ( c i , r i ) ) L_i(e(c_i,r_i)) Li(e(ci,ri)) 表示存在API 调用输出。

给出一个过滤的阈值 τ f \tau_f τf,当满足:
L i − − L i + ≥ τ f L_i^- - L_i^+ \ge \tau_f LiLi+τf
则保留当前的 API 调用,也就是说只有当加入 API 调用后有返回值并且 loss 相比之前降低到到一定的程度,才认为这个 API 调用是有效果的。

例如,下表列出在一定的 τ f \tau_f τf 阈值下的 API 调用是否保留:

2.4 模型微调

过滤完 API 调用之后,构建出新的序列:
x ∗ = x 1 : i − 1 , e ( c i , r i ) , x i : n \mathbf{x}^*=x_{1:i-1},e(c_i,r_i),x_{i:n} x=x1:i1,e(ci,ri),xi:n
采用这种数据集并使用标准的语言模型去微调。

2.5 推理

进行微调后的模型生成文本时,当生成 “→” 的 token 时,表明它接下来期望有一个API 调用的响应。这时中断解码过程,调用适当的 API 来返回响应。在插入响应和 token 后继续解码过程。

3. 三方工具

调用的三方工具上面介绍过,包含:

  1. 问题回答
  2. 计算器
  3. 维基百科搜索
  4. 机器翻译
  5. 日历

工具输入输出示例:

4. 实验结论

4.2 实验设置

数据: 使用 CCNet 的一个子集作为模型训练数据集;

微调: 使用128的批量大小和1×10^-5的学习率对模型进行微调;

对比模型:

  • GPT-J:一个没有任何微调的常规 GPT-J 模型。
  • GPT-J+CC:在没有 API 调用的 CCNet 子集上微调 GPT-J
  • Toolformer:在具有 API 调用数据集上微调 GPT-J
  • Toolformer(disabled)禁用 API 调用的 Toolformer 模型。

4.3 下游任务

评估模型在多种下游任务上的表现,包括 LAMA、数学数据集、问答数据集、多语言问答和时态数据集。使用零样本设置,即模型在没有特定任务的上下文示例的情况下接受任务指令。

Toolformer 在这些任务上的表现显著优于 GPT-J 模型,并且在允许 API 调用时性能得到进一步提升,并且在语言建模能力上没有明显损失。

5. 参考

[1] https://arxiv.org/pdf/2302.04761


欢迎关注本人,我是喜欢搞事的程序猿; 一起进步,一起学习;

欢迎关注知乎/CSDN:SmallerFL

也欢迎关注我的wx公众号(精选高质量文章):一个比特定乾坤
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2085631.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

趣味算法------过河卒

目录 ​编辑 题目描述 解题思路 具体代码 总结 问题描述&#xff1a; 解决方案&#xff1a; 代码实现&#xff1a; 关键点&#xff1a; 题目描述 棋盘上 A 点有一个过河卒&#xff0c;需要走到目标 B 点。卒行走的规则&#xff1a;可以向下、或者向右。同时在棋盘上 C…

海外仓系统是什么?你想要了解的都在这里

对从事海外仓经营的人来说&#xff0c;海外仓系统肯定是不陌生的。但是对一些刚进入海外仓领域的货代代理&#xff0c;或一些家庭海外仓的经营者来说&#xff0c;还是有些糊涂&#xff0c;不知道自己到底要不要引入这样的管理系统&#xff0c;引入海外仓系统之后到底能帮自己做…

尚品汇-订单接口实现(四十)

目录&#xff1a; &#xff08;1&#xff09;搭建service-order-client模块 &#xff08;2&#xff09;微服务之间用户信息传递 &#xff08;3&#xff09;在web-all模块中添加接口 &#xff08;4&#xff09;下订单 &#xff08;1&#xff09;搭建service-order-client模…

DDD设计方法-1-初识DDD

前情提要&#xff1a;一共包含 如下六篇文章&#xff08;篇幅精简&#xff0c;快速入门&#xff09; 1、初识DDD 2、聚合、实体、值对象 3、仓储&#xff0c;封装持久化数据 4、端口和适配器 5、领域事件 6、领域服务&#xff0c;实现约定 DDD设计理念-快速入门 DDD&#xff0…

雨水回用一体化设备

雨水回用一体化设备集提升、回用&#xff08;变频恒压供水&#xff09;、排泥系统&#xff1b;絮凝、消毒&#xff08;加药、紫外线&#xff09;、曝气系统&#xff1b;过滤&#xff08;初、精&#xff09;系统&#xff08;全自动自清洗过滤器/石英砂过滤器/多介质过滤器/精密碟…

没错,一分钟告诉你TCP和UDP之间的区别!

TCP (Transmission Control Protocol&#xff09;和UDP (User Datagram Protocol&#xff09;是两种常用的传输层协议&#xff0c;用于在计算机网络中传输数据。 TCP是一种面向连接的协议&#xff0c;提供可靠的数据传输。它通过建立连接、数据分段、流量控制、拥塞控制和错误校…

【论文阅读】skill code 和 one-shot manipulate

文章目录 1. Interpretable Robotic Manipulation from Language针对痛点和贡献摘要和结论引言模型框架实验思考不足之处 2. One-Shot Imitation Learning with Invariance Matching for Robotic Manipulation针对痛点和贡献摘要和结论引言模型框架实验 1. Interpretable Robot…

深入理解快排【C语言版】

目录 一、快排介绍及其思想 二、hoare版本 三、前后指针版 四、挖坑法 五、优化版本 5.1 三数取中 5.2 小区间优化 六 、非递归实现快排 七、三路划分 八、introsort 小结 一、快排介绍及其思想 快速排序是C.R.A.Hoare于1962年提出的一种划分交换排序。它采用了一…

掌握CompletableFuture,提升你的代码效率!

文章目录 1 CompletableFuture与线程池之间有什么关系&#xff1f;2 如何优化CompletableFuture的性能&#xff1f;3 实际项目中&#xff0c;以并行执行多个HTTP请求为例&#xff0c;你会如何优雅使用CompletableFuture 解决问题&#xff1f; 1 CompletableFuture与线程池之间有…

计算机毕业设计选题推荐-在线音乐网站-音乐专辑商城-Java/Python项目实战

✨作者主页&#xff1a;IT研究室✨ 个人简介&#xff1a;曾从事计算机专业培训教学&#xff0c;擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。 ☑文末获取源码☑ 精彩专栏推荐⬇⬇⬇ Java项目 Python…

埃隆·马斯克超级计算新里程碑:Cortex AI超级集群震撼亮相!

本周&#xff0c;科技界的超级明星埃隆马斯克再次引领潮流&#xff0c;他在超级计算领域的征途上迈出了令人瞩目的步伐。通过一段视频&#xff0c;他首次公开了最新命名的“Cortex”人工智能超级集群&#xff0c;这一壮举不仅标志着特斯拉“Giga Texas”工厂的又一次重大扩张&a…

LeetCode_sql_day17(1843.可疑银行账户)

描述&#xff1a; 表&#xff1a;Accounts ---------------------- | Column Name | Type | ---------------------- | account_id | int | | max_income | int | ---------------------- account_id 是这张表具有唯一值的列。 每行包含一个银行账户每月最大收入的…

提供开发资料 Hi3516CV610-00B/10B/20B/00S/20S/00G/20G 七个型号配置差异

根据功能不同&#xff0c; Hi3516CV610 分为七个不同型号版本: HI3516CV610-00B HI3516CV610-00B HI3516CV610-10B HI3516CV610-20B HI3516CV610-00S HI3516CV610-20S HI3516CV610-00G HI3516CV610-20G

【书生2.1】书生大模型全链路开源体系

0 引言 书生浦语官网 开源一周年总结及回顾 1 回顾 1.1 社区生态 2 总结 书生浦语大模型的开源开放体系&#xff0c;包括技术发展、性能提升、模型架构、开源生态等。 要点: &#x1f31f; 开源开放体系涵盖数据收集、标注、训练、微调、评测、部署等全链路。 &#x1f68…

【案例64】无法从套接字读取更多的数据

问题现象 系统突然间登录报如下错误&#xff1a;SELECT * FROM sm_user WHERE user_code_q? 无法从套接字读取更多的数据 问题分析 查看nc-log.log发现大量相关报错 $$callid1723104097968-1063 $$thread[http-bio-xxx-xxx-exec-xxx] $$hostxxx$$userid#UAP# $$tsxxx-08-08…

C++竞赛初阶L1-14-第六单元-数组(31~33课)542: T456472 数组逆序重存放

题目内容 将一个数组中的值按逆序重新存放。例如&#xff0c;原来的顺序为 8,6,5,4,1。要求改为 1,4,5,6,8。 输入格式 输入为两行&#xff1a;第一行数组中元素的个数 n&#xff08;1<n≤100)&#xff0c;第二行是 n 个整数&#xff0c;每两个整数之间用空格分隔。 输出…

Windows安装PostgreSQL数据库,保姆级教程

PostgreSQL 是客户端/服务器关系数据库管理系统 (RDMS)。PostgreSQL是一个功能非常强大的、源代码开放的客户/服务器关系型数据库管理系统&#xff08;RDBMS&#xff09;。PostgreSQL 也有自己的查询语言&#xff0c;称为 pgsql。 此外&#xff0c;PostgreSQL 还支持过程语言&a…

Cesium模型封装-Point

一、初始化地图 <template><div class"cesium_map"><div id"cesiumContainer"></div></div> </template><script setup> import { reactive, ref, onMounted } from "vue"; import { Point } from &…

基于yolov8的安全帽反光衣护目镜检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的安全帽、反光衣及护目镜检测系统是一款集成了前沿深度学习与计算机视觉技术的智能监控系统。该系统利用YOLOv8这一尖端的目标检测模型&#xff0c;结合云计算与自动化图像处理技术&#xff0c;实现对工地、化工厂、煤矿等高风险作业区域工作人员安全…

Java—方法引用

目录 初识方法引用 方法引用的分类 引用静态方法 引用成员方法 引用构造方法 其它调用方式 类名引用成员方法 引用数组的构造方法 总结 初识方法引用 方法引用就是拿现有的方法来当做函数式接口中抽象方法的方法体。 方法引用注意事项 1. 引用处必须是函数式接口&a…