用形式语言对比大模型微调与上下文学习,发现两者在不同场景下各有优劣。
Fine-tuning vs. In-context Learning in Large Language Models: A Formal Language Learning Perspective
- 设计形式语言任务,严格控制数据和评估标准。
- 微调在分布内泛化上更强,上下文学习在分布外表现相当。
- 上下文学习对模型大小和词汇敏感,适合研究模型偏差。
大型语言模型(LLMs)存在两种基础学习模式:微调(FT)和上下文学习(ICL),这引发关于哪种模式带来更高语言能力以及其归纳偏置是否不同的关键问题。以往研究因实验设置不一致而结果混杂。为实现严谨比较,我们提出一种形式语言学习任务——提供精确的语言边界、受控的字符串采样且无数据污染,并引入判别性测试衡量语言能力:若模型对语言内字符串的生成概率高于语言外字符串,则判定成功。实证发现:(a) 微调在分布内泛化上优于上下文学习,但两者在分布外泛化上表现相当;(b) 当两者部分学习语言时,其归纳偏置相关性相似,但在高能力水平时出现分化;(c) 与微调不同,上下文学习性能随模型规模和家族显著变化,且对语言的词元词汇敏感。本研究展示了形式语言作为评估大模型行为的可控基准的潜力,可分离自然语言数据中难以辨识的行为。代码已开源:https://github.com/bishwamittra/formallm。
原文摘要 · Abstract (English)
Large language models (LLMs) operate in two fundamental learning modes - fine-tuning (FT) and in-context learning (ICL) - raising key questions about which mode yields greater language proficiency and whether they differ in their inductive biases. Prior studies comparing FT and ICL have yielded mixed and inconclusive results due to inconsistent experimental setups. To enable a rigorous comparison, we propose a formal language learning task - offering precise language boundaries, controlled string sampling, and no data contamination - and introduce a discriminative test for language proficiency, where an LLM succeeds if it assigns higher generation probability to in-language strings than to out-of-language strings. Empirically, we find that: (a) FT has greater language proficiency than ICL on in-distribution generalization, but both perform equally well on out-of-distribution generalization. (b) Their inductive biases, measured by the correlation in string generation probabilities, are similar when both modes partially learn the language but diverge at higher proficiency levels. (c) Unlike FT, ICL performance differs substantially across models of varying sizes and families and is sensitive to the token vocabulary of the language. Thus, our work demonstrates the promise of formal languages as a controlled testbed for evaluating LLMs, behaviors that are difficult to isolate in natural language datasets. Our source code is available at https://github.com/bishwamittra/formallm.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。