- The paper finds that fine-tuning consistently outperforms in-context learning on in-distribution syntactic generalization, achieving near-optimal AUC (>0.99) scores.
- Employing hierarchical probabilistic context-free grammars, the study establishes a controlled formal language testbed that isolates syntactic learning effects.
- Token sensitivity analysis reveals that in-context learning performance varies with pre-training token frequency, while fine-tuning remains robust across varying vocabularies.
Fine-Tuning vs. In-Context Learning in LLMs: A Formal Language Learning Analysis
The paper "Fine-tuning vs. In-context Learning in LLMs: A Formal Language Learning Perspective" (2604.23267) provides a comprehensive empirical and methodological comparison between two foundational modes of adaptation for LLMs: full-parameter fine-tuning (FT) and in-context learning (ICL). Prior attempts at comparing FT and ICL have suffered from data contamination, inconsistent resource allocation, or incompatible evaluation metrics. The authors address these confounds by eschewing natural language in favor of probabilistically-structured formal languages, enabling precise control over data distribution, syntactic complexity, and contamination.
They introduce a rigorous experimental framework for evaluating LLM syntactic pattern learning that enforces three desiderata: (1) unambiguous, instruction-free specification of the syntactic learning task via formal grammars; (2) strict resource parity across FT and ICL; and (3) a discriminative evaluation metric that quantifies whether models assign higher generation probability to in-language versus grammatically-close out-of-language strings, thus avoiding model- and prompt-specific effects inherent in generative evaluation.
The study leverages hierarchical probabilistic context-free grammars (HPCFGs), constructing a suite of formal languages (L1โโฆL6โ) varying in recursive depth, probabilistic branching, and token vocabularies. Each language defines a generative distribution over strings, with parameters controlling rule probabilities and symbol emission. Strings are sampled i.i.d. for training and evaluation via FT and ICL, fully avoiding pretraining or contamination effects.
The learning objective in both FT and ICL settings is zero-prompt syntactic generation: given training strings only (no task cue), the LLM is evaluated on its likelihood assignment to novel in-language test strings and confounding out-of-language strings constructed by minimal edit perturbations or random token insertions.

Figure 1: Length distributions of generated strings across the six probabilistic languages, reflecting the diversity and complexity in the evaluation set.


Figure 2: Representative annotated strings from distinct formal languages, illustrating the hierarchical application of non-terminals from their respective grammars.
The LLM cohort encompasses 18 open-source LLMs (0.5Bโ13B parameters) including Mistral, Llama, Qwen, Gemma, Pythia, and Opt, with controlled hyperparameter sweeps for both learning regimes.
Evaluation Methodology: Discriminative Metric for Language Learning Proficiency
Traditional generative metrics (perplexity, cross-entropy) are shown to be misleading for cross-mode or cross-model comparison, due to model- and prompt-dependent priors. The paper introduces a discriminative proficiency metric: area under the ROC curve (AUC) of a classifier discriminating in-language versus out-of-language test strings via their assigned negative log likelihoods. This formulation is robust to confounding factors and enables direct, model-agnostic comparison of FT and ICL.
Main Results: Differential Effects of FT and ICL
In-Distribution Generalization
On in-distribution generalization (training and test data from the same formal language), FT consistently achieves higher discriminative AUC than ICL across nearly all model families and sizes. All LLMs converge to near-optimal FT proficiency (AUC>0.99 given sufficient examples), regardless of architecture or scale, indicating that parameter adaptation allows efficient syntactic pattern extraction in controlled settings.
ICL, in contrast, exhibits substantial variance in proficiency both within and across model families, with AUC values stratifying into "good," "moderate," and "poor" regimes. Notably, ICL performance does not scale monotonically with model size or family advance; for example, Mistral-7B can outperform Mistral-12B. ICL is also highly sensitive to token inventory, with proficiency degraded for languages deploying under-trained or rare tokens.

Figure 3: Out-of-distribution generalization of LLMs trained on a base formal language to incrementally perturbed grammars.
Out-of-Distribution Generalization
On transfer to increasingly distant languages (perturbed grammars), both FT and ICL display sharp performance drops as language distance increases. Both modes predictably generalize only to closely related languages. Importantly, the FT advantage disappears outside the training distribution; ICL and FT perform equivalently in these transfer settings.
Inductive Bias Analysis
The correlation (Pearson) between the per-string generation losses of FT and ICL quantifies similarity of inductive bias. This correlation is positive but decreases as the number of training examples increases, indicating that as models attain greater proficiency, the internal mechanisms by which FT and ICL solve the task diverge. This effect is robust across languages and model families.



Figure 4: Inductive bias of FT vs. ICL, as measured by loss correlation, decreasing with more examples.
Token Sensitivity and Robustness
ICL performance is acutely sensitive to the token set defining the language, exhibiting major proficiency drops when target tokens are rare or under-trained in pre-training. FT is substantially more robust, exhibiting consistently high proficiency regardless of the specific terminal set or underlying grammar.
Figure 5: A string s generated by the grammar, demonstrating the compositional patterning LLMs are evaluated on.
Implications and Theoretical Consequences
- FT is strictly preferable for consistent syntactic generalization when the training and test language coincide, as it reliably pushes model parameters into the appropriate representation subspace irrespective of pre-training token frequency.
- ICL is less robust, more variable, and highly subject to both pre-training coverage and family-specific architectural details. As such, conclusions drawn from ICL-based few-shot UX studies in natural language applications may not generalize.
- Neither FT nor ICL confers a transferable advantage for syntactic or structural generalization outside the training distributionโboth modes are bounded by the parametric inductive horizon of the training grammar in the absence of semantic signal.
- Inductive biases of FT and ICL diverge at high proficiency, suggesting that conclusions about LLM learning mechanisms drawn from ICL benchmarks may not extrapolate to fine-tuned regimes and vice versa.
- Resource allocation and evaluation metric are critical confounds in prior natural language comparisonsโonly the discriminative test coupled with formal languages provides reproducible, contamination-free behavior characterization.
Practical Consequences and Future Directions
- In LLM-powered systems requiring robust acquisition of novel syntactic regularities, FT is the preferred adaptation path provided training and test domains are aligned and compute is available.
- For settings where token distributions differ substantially from pre-training, FT mitigates performance bottlenecks that undermine ICL generalization.
- The formal language testbed enables deeper empirical dissection of LLM inductive bias, memory capacity, and adaptation strategies, isolated from semantic bleed-through and data contamination.
- Further investigation is warranted into parameter-efficient fine-tuning strategies, instruction-tuned models, and extension to classes of formal languages beyond context-free, particularly to context-sensitive grammars.
Conclusion
The study sets a new standard for the methodological comparison of LLM adaptation modes by introducing a controlled, syntactic-only formal language setting and a discriminative evaluation protocol. The findings establish that while FT and ICL yield similar proficiency at low sample counts or partial language acquisition, FT reliably dominates for in-distribution syntactic generalization and is markedly more robust to token distributional shift. Out-of-distribution generalization remains challenging for both modes. The work argues convincingly for widespread adoption of formal and discriminative testbeds for rigorous LLM evaluation.