In-Context Compilation: Encoding Context-Induced Behavioral Shift into Model Weights

Michael Merzin, Yehonatan Elisha, Oren Barkan, Yonatan Toib, Noam Koenigstein


Abstract
In-context learning (ICL) adapts LLM behavior by placing task-relevant context in the prompt. While powerful, this mechanism can be inefficient: the context must be reprocessed for every query, and when it is substantially longer than the query itself, it dominates inference cost in both latency and token overhead. This paper contends that the behavioral shift induced by an in-context signal can be compiled directly into the model weights, enabling subsequent inference without including the original context in the prompt. To this end, we propose In-Context Compilation (ICC), a gradient free method that encodes a context-induced behavioral shift as a sparse closed-form edit to attention output-projection weights. ICC is calibrated solely from the activation differences between no-context and with-context forward passes on a small set of behaviorally informative examples, requiring neither backpropagation nor trainable parameters. We evaluate ICC in the few-shot setting, where labeled contexts provide controlled behavioral targets. Across diverse LLM architectures and classification and reasoning benchmarks, the ICC-adapted LLM closely approximates the performance of the same LLM prompted with the full context, while omitting that context at inference time. In some cases, it even surpasses the with-context model. Moreover, on most benchmarks, ICC is competitive with and often outperforms gradient-based PEFT methods (LoRA, DoRA, IA3, Prompt/Prefix Tuning, LoReFT) and training-free activation-injection baselines (Function Vectors, ICV), while completing compilation in 10–18s with only ∼64–120 MB of overhead.
Anthology ID:
2026.findings-emnlp.983
Volume:
Findings of the Association for Computational Linguistics: EMNLP 2026
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Hung-Yi Lee, Sunipa Dev, Jessy Li, Desmond Elliott
Venue:
Findings
SIG:
SIGDAT
Publisher:
Association for Computational Linguistics
Note:
Pages:
20777–20796
Language:
URL:
https://aclanthology.org/2026.findings-emnlp.983/
DOI:
Bibkey:
Cite (ACL):
Michael Merzin, Yehonatan Elisha, Oren Barkan, Yonatan Toib, and Noam Koenigstein. 2026. In-Context Compilation: Encoding Context-Induced Behavioral Shift into Model Weights. In Findings of the Association for Computational Linguistics: EMNLP 2026, pages 20777–20796, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
In-Context Compilation: Encoding Context-Induced Behavioral Shift into Model Weights (Merzin et al., Findings 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.findings-emnlp.983.pdf