Fine-tuning vs. In-context Learning in Large Language Models: A Formal Language Learning Perspective
Bishwamittra Ghosh, Soumi Das, Till Speicher, Qinyuan Wu, Mohammad Aflah Khan, Deepak Garg, Krishna P. Gummadi, Evimaria Terzi · 2026
Read Fine-tuning vs. In-context Learning in Large Language Models: A Formal Language Learning Perspective by Bishwamittra Ghosh, Soumi Das, Till Speicher, Qinyuan Wu, Mohammad Aflah Khan, Deepak Garg, Krishna P. Gummadi, Evimaria Terzi (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2604-23267.txt.
Introduction
Ghosh and seven colleagues compare fine-tuning and in-context learning in large language models through formal language tasks with controlled sampling. A discriminative test counts an LLM as proficient when it assigns higher probability to in-language strings than to out-of-language ones. Fine-tuning beats in-context learning on in-distribution generalisation, while both match on out-of-distribution generalisation. Inductive biases look similar at partial learning but diverge at higher proficiency, while in-context learning varies more across models and reacts to token vocabulary.
Catalog record
| CREATOR | Bishwamittra Ghosh, Soumi Das, Till Speicher, Qinyuan Wu, Mohammad Aflah Khan, Deepak Garg, Krishna P. Gummadi, Evimaria Terzi |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 112638 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2604.23267
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Fine-tuning vs. In-context Learning in Large Language Models: A Formal Language Learning Perspective Bishwamittra Ghosh, Soumi Das, Till Speicher, Qinyuan Wu, Mohammad Aflah Khan, Deepak Garg, Krishna P. Gummadi, Evimaria Terzi Abstract Large language models (LLMs) operate in two fundamental learning modes – fine-tuning ( 𝙵𝚃 \mathtt{FT} ) and in-context learning ( 𝙸𝙲𝙻 \mathtt{ICL} ) – raising key questions about which mode yields greater language proficiency and whether they differ in their inductive biases. Prior studies comparing 𝙵𝚃 \mathtt{FT} and 𝙸𝙲𝙻 \mathtt{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) 𝙵𝚃 \mathtt{FT} has greater language proficiency than 𝙸𝙲𝙻 \mathtt{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 𝙵𝚃 \mathtt{FT} , 𝙸𝙲𝙻 \mathtt{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 . 1 Introduction Large language models (LLMs) operate in two fundamental learning modes: fine-tuning ( \mathtt{FT} ) and in-context learning ( \mathtt{ICL} ). \mathtt{FT} simulates a closed-book exam, where LLMs learn by updating model parameters Kaplan et al. 2020 . \mathtt{ICL} simulates an open-book exam, where LLMs learn from in-context examples without any parameter update Brown et al. 2020 . Both modes are widely applied in real-world tasks, including text summarization Radford et al. 2019 , question-answering Yang et al. 2018 , and conversational agents Ouyang et al. 2022 . A natural question is, therefore, which learning mode is more language-proficient , i.e., which mode recognizes patterns in the language better, and whether their inductive bias , i.e., the implicit assumptions about recognizing patterns, is similar or different. Despite its importance, this question remains open due to inconsistent experimental setups in prior studies. s^{(1)} s^{(2)} \ldots s^{(n)} Training Strings \mathtt{Model} ( \theta \rightarrow \theta^{*} ) \mathtt{Model} (\theta^{*}) s Test String \mathtt{Loss}( s \mid \theta^{*} ) Fine-Tuning \mathtt{Model} (\theta) [ s^{(1)};\;s^{(2)};\;\ldots;\;s^{(n)}; s ] Prompt (concatenated input) \mathtt{Loss}( s \mid s^{(1)},\ldots,s^{(n)} ; \theta ) In-context Learning Figure 1: Fine-tuning and in-context learning are two learning modes of an LLM. In formal language learning, the learning task is to generate unseen strings from the language through syntactic pattern recognition (desideratum D1 ). Under an equal setting (desideratum D2 ), fine-tuning updates model parameters ( \theta \rightarrow \theta^{*} ) based on the training strings and computes the generation loss on a test string . In-context learning, however, takes a concatenated input prompt, where training strings serve as the prefix for generating the test string . Since the two learning modes differ in both input prompt and model parameters, a comparable evaluation metric is needed (desideratum D3 ). Addressing this gap requires a principled experimental design. Our Contributions. Our key contribution is the introduction of the following three-fold desiderata for comparing \mathtt{FT} and \mathtt{ICL} , and a controlled experimental framework that realizes these desiderata (see motivation in Figure 1 ). Several prior studies attempted to compare \mathtt{FT} and \mathtt{ICL} without satisfying all three desiderata, resulting in mixed and inconclusive results. Specifically, the closest to our work is Mosbach et al. 2023 , who partially satisfy desiderata D1 and D2 , but fail to satisfy D3 . D1. Specification of the Learning Task: Syntax-focused Learning with Zero-prompting. We compare \mathtt{FT} and \mathtt{ICL} on learning a probabilistic formal language , which is a distribution of strings accepted by a probabilistic formal grammar Manning 2003 ; Chater and Manning 2006 . The learning task is to generate new strings based on recognizing syntactic patterns of the underlying language represented by the training strings (Section 3 ). Formal languages offer several advantages for this comparison: (a) they contain syntax only, isolating syntactic pattern recognition from the semantic ambiguity of natural languages – the main focus of prior studies Mosbach et al. 2023 ; (b) they provide full control over data distribution, enabling precise sampling of training and test strings and differentiation between in-distribution and out-of-distribution languages; (c) they are synthetic, avoiding data contamination and ensuring no model benefits from prior knowledge of the training data Xu et al. 2024 . These properties are difficult to guarantee with natural language datasets. A practical challenge in comparing learning modes is communicating the task via prompt-instructions , which different LLMs may interpret differently Wu et al. 2025 ; Zhao et al. 2021 ; Razavi et al. 2025 ; Zhuo et al. 2024 . Formal language learning sidesteps this subjectivity: we consider a zero-prompting setup where the LLM only sees training strings and must generate new strings without any instruction. D2. Allocation of Equal Resources. A fair comparison requires allocating equal resources to both \mathtt{FT} and \mathtt{ICL} 1 1 1 Resource fairness includes data and compute fairness. The paper focuses on data fairness. Achieving compute fairness, however, is challenging, since \mathtt{FT} and \mathtt{ICL} incur costs at different stages: \mathtt{FT} is costly during training, while \mathtt{ICL} is costly at inference (Figure 41 in the Appendix). . We provide the same training and test data to both learning modes. Since \mathtt{FT} and \mathtt{ICL} have disjoint hyperparameters – batch-size, learning rates, and epochs for \mathtt{FT} ; example repetitions and inference temperature for \mathtt{ICL} – we compare their best performance over respective hyperparameter settings, going beyond prior work ( Mosbach et al. 2023 ; Yin et al. 2024 ) that addresses this only partially. D3. Comparable Evaluation Metric. How can we evaluate the language proficiency of a learner in a language? There are two potential tests for language proficiency: generative and discriminative – the latter introduced in this work. The generative test computes the generation probability of in-language strings, but this is not directly comparable: LLMs vary in their priors, and \mathtt{FT} and \mathtt{ICL} of the same LLM but with different parameters treat the input prompt differently (Figure 1 ), making a direct numerical comparison of generation probability infeasible. The discriminative test instead checks whether in-language strings are generated with higher probability than close yet grammatically incorrect out-of-language strings, and results in a classification score – a metric that avoids model-specific and prompt-specific biases, making it comparable across both modes. Therefore, we claim that the discriminative test is the appropriate metric for comparing \mathtt{FT} and \mathtt{ICL} (Section 4 ). Experimental Results. We experiment with 18 open-source LLMs from 6 model families and multiple formal languages, and reach the following conclusions: (a) Different LLMs converge to optimal \mathtt{FT} performance, while their \mathtt{ICL} ability varies substantially in formal languages. Model size contributes to improved performance in \mathtt{ICL} but not in \mathtt{FT} . (b) On in-distribution generalization, where training and test languages are the same,