Agentic AI Notes / 02 of 02 / A different world
Can what a model learned in one place help it succeed somewhere new and different?
The idea in one line
Transfer is about reusing what was learned on one task or in one setting to get a head start on a different but related one. Instead of starting from zero, you carry over features, representations, or learned weights across the boundary.
This is the difference between generalization and transfer. Generalization asks about new examples from the same world. Transfer asks about a different world, and adds a price for how far apart the two worlds are.
Someone who already speaks Spanish learns Italian far faster than someone starting fresh. The grammar, the shared roots, the instincts all carry over. But the same head start can mislead them, because a few familiar-looking words mean something entirely different. Transfer is exactly this: a powerful shortcut that occasionally trips you up.
What moves across
A consistent finding: early layers of a network learn general-purpose structure that transfers easily, while later layers specialize and transfer poorly. The further apart the two settings, the less of the model you can safely keep.
The three-term rule
The theory of learning across domains breaks target error into three honest pieces. You can reason about a transfer project just by asking about each one.
How well the model does in the original setting. Usually the easy part, since that is where the labels and control live.
How distinguishable the source and target data are. If a simple detector can instantly tell them apart, this term is large and dominates everything.
Is there any single model that could do well in both worlds at once? If the underlying rule genuinely differs, this term is large and no alignment can save the transfer.
Theory, in more depth
The Ben-David target-error bound makes the three pieces precise. For a hypothesis \(h\), source \(S\), target \(T\):
The middle term is a divergence between the two marginal feature distributions, measured through the lens of the hypothesis class. Crucially it is something you can estimate: it relates to how well any classifier in your family can tell source from target. If the best domain discriminator has error \(\epsilon_{\mathrm{disc}}\), then
So a discriminator that is near perfect (\(\epsilon_{\mathrm{disc}}\to 0\)) pushes the divergence toward its maximum of 2, and one reduced to a coin flip (\(\epsilon_{\mathrm{disc}}\to 0.5\)) drives it to 0. This single relationship motivates the entire feature-alignment program.
When only the inputs shift (\(p_S(x)\ne p_T(x)\) but \(p(y\mid x)\) is stable), the optimal correction is importance weighting by the density ratio \(p_T(x)/p_S(x)\). In high dimensions that ratio is hard to estimate, which is why feature alignment usually wins in practice.
These methods reshape features until source and target overlap. MMD minimizes the maximum mean discrepancy in a reproducing-kernel space. CORAL aligns second-order statistics, the feature covariances, cheaply and effectively. Adversarial adaptation (a gradient-reversal layer) trains a domain classifier to separate source from target while the encoder is trained to fool it, directly minimizing the divergence term above. Optimal-transport approaches replace the divergence with a Wasserstein cost, which behaves better when the two supports barely overlap.
Fine-tuning is the workhorse: pretrain on a large source, then freeze early layers and retrain a head, or fine-tune end to end. Parameter-efficient methods (low-rank adapters such as LoRA) add a small update and keep the base frozen, betting that the needed adaptation lives in a low-dimensional subspace. Distillation transfers the learned function rather than the weights: the student matches the teacher's soft outputs, whose relative magnitudes carry the teacher's learned similarity structure. This composes naturally with quantization for embedded targets.
The harder cousin: no target data at all during training, only several source domains, with the goal of generalizing to an unseen one. Approaches include invariant risk minimization, which seeks features whose optimal predictor is stable across environments; meta-learning, which simulates domain shift in an inner loop; and group distributionally-robust optimization, which minimizes the worst-group risk rather than the average.
You have labeled fault data from three motor platforms, call them A, B, and C, across several model years. A fourth platform D is launching and you will have no labeled faults from it. This is neither plain generalization (D is a genuinely different world) nor standard adaptation (you cannot see D during training). It is domain generalization, the ground between the two pages.
Pool A, B, and C and train one model, and it quietly latches onto whatever spurious cue happens to track faults across those three, for instance a mounting resonance shared by A and B. Platform D may not share it, and accuracy collapses on launch.
Treat each platform as its own environment and reward features whose fault-versus-healthy decision is stable across all three. A cue that predicts faults equally well on A, B, and C is more likely capturing real bearing physics than a platform artifact, so it should survive on D. Training against the worst environment, rather than the average, hardens the model against the platform that behaves least like the others.
Leave one platform out: train on A and B, test on C; then A and C, test B; then B and C, test A. The worst of those three scores is your honest estimate for the unseen D. If the score swings wildly depending on which platform is held out, the model is still leaning on platform-specific cues.
Worked example · Vehicle Health Management
A bearing-fault detector. The source is a dynamometer rig or a high-fidelity simulation with seeded inner and outer-race faults, so labels are plentiful and conditions are controlled. The target is real vehicles in the field, where labels are scarce and operating conditions vary wildly.
\(\epsilon_S\) is tiny. A convolutional model on the order-tracked spectrum nails seeded rig faults at over 98 percent. Not the problem.
Train a discriminator to tell rig features from fleet features. On raw spectra it hits about \(\epsilon_{\mathrm{disc}}\approx 0.05\): constant test-stand speed versus varying road load, clean bench versus road noise, different sensor mounting all make the two worlds trivially separable. Then \(d_{\mathcal{H}\Delta\mathcal{H}}\approx 2(1-0.10)=\) 1.8 out of 2. The bound is effectively vacuous: source accuracy tells you nothing about the fleet.
Is \(\lambda\) small? It is nonzero if the fault signature itself differs, for instance a different bearing geometry shifting the characteristic defect frequencies, or a sampling rate that aliases the rig's fault harmonics on the vehicle. Check this first. If \(\lambda\) is large, no amount of alignment helps and you need target labels.
Adversarial or covariance alignment reshapes features until the discriminator degrades. Push \(\epsilon_{\mathrm{disc}}\) from 0.05 toward 0.40, and \(d_{\mathcal{H}\Delta\mathcal{H}}\) drops from 1.8 to about \(2(1-0.80)=\) 0.4. The bound becomes usable, and target accuracy realistically climbs from a coin flip into the 80s.
Matching the shape of the data is blind to what the labels mean. The classic failure: a spectral feature that signals an outer-race fault on the steady rig coincides with a benign road resonance on the vehicle. Force the marginals to align and you drag benign vehicle data onto the fault manifold, producing confident false alarms that are worse than no transfer at all.
Keep a few labeled fault examples from the real fleet. They pin down \(\lambda\), expose any conflict early, and let you align by class (conditional alignment) rather than blindly by shape.
Aligning the marginals \(p(x)\) does nothing to guarantee the conditionals \(p(y\mid x)\) agree. When they disagree, aggressive marginal alignment can provably increase target error rather than reduce it. This is the formal content of the negative-transfer warning, and the reason conditional and class-aware alignment exist.
Measure it in practice
The divergence term is not just theory; it is a number you can estimate before committing to a transfer effort. Train a simple classifier to tell source features from target features. The better it does, the further apart the two worlds are, and its accuracy converts directly into the A-distance, a practical proxy for the divergence in the bound.
from sklearn.linear_model import LogisticRegression from sklearn.model_selection import cross_val_score import numpy as np # Z_src, Z_tgt: learned features from each domain Z = np.vstack([Z_src, Z_tgt]) d = np.r_[np.zeros(len(Z_src)), np.ones(len(Z_tgt))] # domain label auc = cross_val_score(LogisticRegression(max_iter=1000), Z, d, scoring='roc_auc', cv=5).mean() eps = 1 - auc # discriminator error proxy a_distance = 2 * (1 - 2 * eps) # near 0 aligned, near 2 far apart print(auc, a_distance)
Run it before and after alignment. A pre-alignment A-distance near 2 that drops near 0 afterward is the signal that adaptation is doing real work rather than cosmetic feature shuffling.
Transfer is what an agent does every time it meets a new tool, API, or environment. In-context examples are a fast form of transfer; fine-tuning a base model into a specialist is a slow one. The three-term rule still holds: the agent's skill in the old setting, how different the new environment is, and whether any single policy could handle both. When a capable agent fails on an unfamiliar tool, the usual culprit is the divergence term, not a lack of intelligence.
References