arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2208.01066cs.CLcs.LG
收藏

Transformer 能在上下文中学习什么?简单函数类的案例研究

What Can Transformers Learn In-Context? A Case Study of Simple Function Classes

Stanford University(斯坦福大学)

Shivam Garg, Dimitris Tsipras, Percy Liang, Gregory Valiant

AI总结:

本文通过简单函数类案例研究 Transformer 的上下文学习能力,证明其能从零训练学习线性函数及更复杂的稀疏线性函数、两层神经网络和决策树,且在分布偏移下仍有效,性能可匹配或超越特定任务算法。

摘要:

上下文学习(in-context learning)是指模型能够以提示序列为条件进行推理的能力,该提示序列由上下文示例(对应于某个任务的输入-输出对)以及一个新的查询输入组成,并生成相应的输出。关键在于,上下文学习仅发生在推理阶段,不需要对模型进行任何参数更新。虽然 GPT-3 等大型语言模型表现出一定的上下文学习能力,但目前尚不清楚这种能力成功的任务与训练数据中存在的内容之间的关系。为了推进对上下文学习的理解,我们考虑一个定义明确的问题:训练一个模型对某个函数类(例如线性函数)进行上下文学习——也就是说,给定来自该类中某些函数的数据,我们能否训练一个模型对该类中的“大多数”函数进行上下文学习?我们通过实验证明,标准的 Transformer 可以从零开始训练,以执行线性函数的上下文学习——即训练后的模型能够从上下文示例中学习未见过的线性函数,其性能可与最优最小二乘估计器相媲美。事实上,即使在两种分布偏移形式下,上下文学习也是可能的:(i)模型的训练数据与推理时的提示之间存在分布偏移,以及(ii)推理时上下文示例与查询输入之间存在分布偏移。我们还表明,我们可以训练 Transformer 对更复杂的函数类进行上下文学习——即稀疏线性函数、两层神经网络和决策树——其性能可匹配或超过特定任务的学习算法。我们的代码和模型可在 https://github.com/dtsip/in-context-learning 获取。

英文摘要:

In-context learning refers to the ability of a model to condition on a prompt sequence consisting of in-context examples (input-output pairs corresponding to some task) along with a new query input, and generate the corresponding output. Crucially, in-context learning happens only at inference time without any parameter updates to the model. While large language models such as GPT-3 exhibit some ability to perform in-context learning, it is unclear what the relationship is between tasks on which this succeeds and what is present in the training data. To make progress towards understanding in-context learning, we consider the well-defined problem of training a model to in-context learn a function class (e.g., linear functions): that is, given data derived from some functions in the class, can we train a model to in-context learn "most" functions from this class? We show empirically that standard Transformers can be trained from scratch to perform in-context learning of linear functions -- that is, the trained model is able to learn unseen linear functions from in-context examples with performance comparable to the optimal least squares estimator. In fact, in-context learning is possible even under two forms of distribution shift: (i) between the training data of the model and inference-time prompts, and (ii) between the in-context examples and the query input during inference. We also show that we can train Transformers to in-context learn more complex function classes -- namely sparse linear functions, two-layer neural networks, and decision trees -- with performance that matches or exceeds task-specific learning algorithms. Our code and models are available at https://github.com/dtsip/in-context-learning .

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑