When Thoughts Become Memory: Unifying In-Context Learning and Fine-Tuning
Organizations: Hassana Labs.
Abstract
We are the first to give a certified rule for whether unseen data belong in a pretrained model's context or its weights, built on an exact law for their information value. That value, the code length saved on held-out queries, equals in expectation the bits stored about the query, plus a prior repair, minus a decoding loss, for any model, architecture, dataset and task. The law's ceilings certify the choice from one measurement, and an anytime-valid test makes it from held-out queries, with error controlled whenever it stops. Every certificate the ceilings issue on a trained transformer, TabPFN, an occupancy network and a stereo network is correct. The test picks TabPFN over XGBoost and a trained surrogate over an in-context learner on airfoil pressure, calls the better of GPT-2's cache and fine-tune in 61,948 of 64,000 query streams over 32 comparisons, and errs in at most 3.3% of null streams. The law also diagnoses when learning in context helps and when it does not. Deleting part of a context is held-out validation of that part in any model, and adding parts one at a time traces the learning curve in context: one patch that sees a shape feature cuts an occupancy network's code length there a hundredfold, while eight that miss it nearly double it, and one camera that sees the surface beats four in a stereo network. Ranked by this label-free valuation, a kriging learner's three best support cars beat four drawn at random, and on a yes-or-no claim the valuation recovers a published evidence adjudicator, with AUROC 0.91.
Figures & tables
| Tool | What it takes | What it guarantees | Tested on, and checked by |
| With the information terms of the data | |||
| Exact law (Thm. 2 ) | held-out code lengths | , in context and in the weights alike | every term in closed form for a linear-Gaussian model, matched by simulation (App. A.10 ) |
| Certificates (Prop. 6 (ii)) | one channel’s code length, the other’s ceiling | the channel beats every memory confined to the window, or of at most bits | 25 of 64 on a trained transformer and 36 of 96 on TabPFN, occupancy and stereo networks, all correct |
| From the model’s probabilities and reruns alone | |||
| Decoding-loss bound (Prop. 6 (iii)) | a fine-tune’s advantage, context in the window | no fine-tune adds more than the decoding loss in context | GPT-2: at least 0.35–0.55 bits per token, prior repair the cache leaves unrealised |
| Anytime-valid test (Thm. 8 ) | held-out code lengths of both channels | a wrong call with probability at most , whenever the test stops | tables, airfoil pressure and GPT-2; at most 3.3% wrong calls on nulls, within 5%; a power curve; the same call in 200 reorderings |
Appendix figures & tables23 assets
Supplementary material from the paper’s appendix.
Appendix
| Task | Model and data | Memory built from the context | Deleted context | Output law and claim | Scale |
|---|---|---|---|---|---|
| Controlled occupancy | Pretrained ConvONet; constructed chairs | Feature grid from the observed points | 300 observed surface points | Bernoulli occupancy; the site is occupied | 8 shape pairs; 1,024 feature sites per pair; relevant and matched deletions of equal size |
| Donor replacement | Same ConvONet; ShapeNet objects | Feature grid | Optional point-cloud observations | Bernoulli occupancy at fixed world coordinates | 16 objects; 8,492 fixed claims; independent donor-mesh labels |
| Multi-view depth | Pretrained MVSNet; DTU | Cost volume over the source views | Source image and camera | Categorical depth law; depth in a fixed interval | 5 scenes, 25 reference views; paired observing and non-observing deletions |
| Pressure fields | Kriging learner; DrivAerNet | Kriging weights, recomputed for each site | Support car (geometry and pressure) | Gaussian pressure law; pressure within a fixed tolerance | 8 query cars, 6 support cars each; 512 area-weighted sites |
| Language verification | Trace Budget adjudicator; VitaminC | Key–value cache | Evidence passage | Probability of the fixed claim | 800 examples; Qwen2.5-7B-Instruct and GPT-4.1-mini |
| Condition | Mean | Gain (bits) | |
|---|---|---|---|
| Feature item deleted | 0.001410 | 17.6642 | 7,473 |
| Matched item deleted | 0.983387 | 0.00111 | 70 |
| Recessed shape observed | 0.002191 | 17.4116 | — |
| Deleted source view | Observing | Non-observing |
|---|---|---|
| Full probability | 0.8952 | 0.8952 |
| Ablated probability | 0.7552 | 0.8504 |
| Gain (bits) | 1.6204 | 0.5452 |
| Claim-level bits | 0.8391 | 0.1872 |
| Target crossings | 1,840 | 760 |
| Reverse crossings | 153 | 455 |
| Deletion | Required | Supplied | Claim | Crossings |
|---|---|---|---|---|
| Feature item | 16.93 | 17.66 | 17.66 | 7,473/7,473 |
| Matched item | 0.006 | 0.001 | 0.001 | 70/7,473 |
| Observing view | 1.27 | 1.62 | 0.84 | 1,840/8,251 |
| Non-observing view | 0.53 | 0.55 | 0.19 | 760/8,251 |
| One support car | 0.74 | 0.23 | 0.04 | 4.3% of area |
| Reduced input | Native inference | |
|---|---|---|
| Geometry points | 512 | 32,000 |
| Chart anchors | 128 | 1,024 |
| Leave-one-out points | 512 | 4,000 |
| Mean relative error | 0.5276 | 0.2992 |
| Mean single-car gain (bits) | 0.7939 | 0.2296 |
| Metric | Qwen2.5-7B | GPT-4.1-mini |
| Sufficiency AUROC (515) | 0.9126 | 0.9143 |
| Full-grounding AUROC (800) | 0.8990 | 0.9297 |
| NEI flagged / 120 | 114 | 112 |
| Refutes flagged / 285 | 261 | 275 |
| Supports flagged / 395 | 103 | 99 |
| Correct paired direction / 390 | 370 | 371 |
| Occupancy network, patches | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| Feature patch first | 4.99 | 0.046 | 0.021 | 0.019 | 0.014 | 0.016 | 0.014 | 0.015 | 0.015 | 0.015 |
| Random order | 4.99 | 5.13 | 5.26 | 4.68 | 4.31 | 3.86 | 3.40 | 2.78 | 1.96 | 0.015 |
| Feature patch last | 4.99 | 5.71 | 6.39 | 7.25 | 8.01 | 8.25 | 8.72 | 8.90 | 9.06 | 0.015 |
| Stereo network, source views | 1 | 2 | 3 | 4 | ||||||
| Observing views first | 8.71 | 8.61 | 9.73 | 10.17 | ||||||
| All subsets of the size | 13.65 | 10.97 | 10.14 | 10.17 |
| Window 8 | Window 16 | ||||||
|---|---|---|---|---|---|---|---|
| Fine-tune | cache | tune | won | cache | tune | won | |
| Full | 0 | 4 | 4/4/1 | 0 | 3 | 5/3/1 | |
| Adapter | 2 | 6 | 0 | 7/0/0 | 6 | 0 | 7/0/0 |
| Adapter | 4 | 0 | 0 | 7/0/0 | 5 | 0 | 7/0/0 |
| Adapter | 8 | 0 | 0 | 6/0/1 | 0 | 0 | 7/0/0 |
| Adapter | 16 | 0 | 2 | 2/4/1 | 0 | 0 | 7/0/0 |
| Comparison | Seed | In context | Trained | Accuracy (%) | Call | Queries | Orders |
|---|---|---|---|---|---|---|---|
| Phoneme: TabPFN vs XGBoost | 0 | 0.587 | 0.761 | 78.2 / 78.3 | in context | 348 | 200/200 |
| 1 | 0.605 | 0.691 | 76.6 / 78.9 | in context | 1,390 | 200/200 | |
| 2 | 0.640 | 0.965 | 77.9 / 78.2 | in context | 151 | 200/200 | |
| Spambase: TabPFN vs XGBoost | 0 | 0.379 | 0.716 | 91.5 / 85.8 | in context | 198 | 200/200 |
| 1 | 0.299 | 0.501 | 92.7 / 88.7 | in context | 247 | 200/200 | |
| 2 | 0.318 | 0.454 | 91.7 / 88.1 | in context | 358 | 200/200 |
| Designs | In context | Trained | Call in seeds 0, 1, 2 |
|---|---|---|---|
| 4 | 4.964 | — | — |
| 8 | 4.718 | — | — |
| 16 | 4.583 | 4.746 | none, context, none |
| 32 | 4.258 | 4.292 | trained, context, context |
| 64 | 3.951 | 3.573 | trained, context, trained |
| 128 | 3.649 | 2.341 | trained, trained, trained |
| Case | Wrong calls | 95% upper | Correct calls by 256 / 1,024 / 4,096 | ||
| Exact tie | 0.00% | 0.04% | — | ||
| Symmetric null | 3.25% | 3.62% | — | ||
| Skewed null | 2.87% | 3.22% | — | ||
| Null of changing variance | 3.31% | 3.68% | — | ||
| Advantage 0.5 | 0.00% | 0.04% | 88.1% | 100.0% | 100.0% |
| Advantage 0.1 | 0.17% | 0.27% | 3.7% | 12.3% | 54.9% |
| Code length | |||||||
|---|---|---|---|---|---|---|---|
| Task | Context | Recipe | Cache | Fine-tune | Better memory | Calls | Queries |
| Shakespeare | 4 units | online | 6.98–7.23 | 6.59–6.68 | fine-tune | 8,000/8,000 | 205–324 |
| Shakespeare | 256 units | online | 6.80–7.13 | 5.68–5.70 | fine-tune | 8,000/8,000 | 81–103 |
| Recall | 512 tokens | 1 epoch | 0.62–1.92 | 5.44–6.64 | cache | 8,000/8,000 | 25–29 |
| Recall | 512 tokens | 4 epochs | 0.62–1.92 | 2.91–4.46 | cache | 8,000/8,000 | 46–69 |
| Recall | 512 tokens | 16 epochs | 0.62–1.92 | 0.23–0.36 | fine-tune | 8,000/8,000 | 70–300 |
| Model | Window | Capacity | Checks | Agree | Disagree |
|---|---|---|---|---|---|
| TabPFN-v2 | 8/30 | 17/48 | 50 | 50 | 0 |
| Occupancy network | 2/5 | 3/6 | 14 | 14 | 0 |
| MVSNet | 2/3 | 4/4 | 22 | 22 | 0 |
| All | 12/38 | 24/58 | 86 | 86 | 0 |
| Donor mesh relation | Claims | Still at 0.95 | Pooled rate | Equal-object rate |
|---|---|---|---|---|
| Agrees with fixed claim | 5,902 | 5,305 | 89.88% | 78.34% |
| Disagrees with fixed claim | 2,589 | 64 | 2.47% | 2.30% |
| Boundary ambiguous | 1 | 0 | 0% | 0% |
| Scene | Oracle inside | Oracle outside | Boundary |
|---|---|---|---|
| 9 (protocol development) | 3.3232 | 0.7735 | 1.9261 |
| 4 | 3.9743 | 6.3977 | |
| 48 | 13.8833 | 4.1997 | 7.1883 |
| 11 | 10.6232 | 3.7646 | 4.4055 |
| 29 | 15.7790 | 2.5745 | 11.3640 |
| Mean, all five scenes | 9.5166 | 2.1136 | 6.2563 |
| Inference | Claim bank | Gain | Claim bits | Crossing | Reverse | ||
|---|---|---|---|---|---|---|---|
| Reduced input | Reduced-input answer | 0.5761 | 0.5312 | 0.7939 | 0.1108 | 4.6045% | 1.6273% |
| Reduced input | Native answer | 0.4623 | 0.4806 | 0.7939 | 0.1056 | 1.4881% | 2.6273% |
| Native | Reduced-input answer | 0.4629 | 0.4584 | 0.2296 | 0.0382 | 1.2688% | 1.3699% |
| Native | Native answer | 0.6131 | 0.5895 | 0.2296 | 0.0419 | 4.2862% | 2.2225% |
In-Context Learning
In-context learning studies how models adapt to new tasks from examples or instructions supplied at inference time, without changing their weights.
See all 402 papers