← Back to Autonomy

Agentic AI Notes / 02 of 02 / A different world

Knowledge
Transfer

Can what a model learned in one place help it succeed somewhere new and different?

εtarget ≤ εsource + ½ divergence(source, target) + λ Error in the new world is at most your error in the old world, plus how different the two worlds are, plus whether any single model could ever do well in both. The middle term usually decides everything.

The idea in one line

Different world, borrowed learning

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

Four things you can carry over

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

Why transfer succeeds or fails

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.

term one
Source error εsource

How well the model does in the original setting. Usually the easy part, since that is where the labels and control live.

term two · the one that bites
How different the worlds are divergence

How distinguishable the source and target data are. If a simple detector can instantly tell them apart, this term is large and dominates everything.

term three
Best joint model λ

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.

BEFORE: worlds far apart source target AFTER: aligned features overlap Alignment pulls the two distributions together so a model trained on the source can no longer tell which world a feature came from. caution: aligning only the shapes, while the labels mean different things in each world, can make results worse, not better.
The main job of domain adaptation is to shrink term two: reshape features until the two worlds overlap. The warning at the bottom is the negative-transfer trap.

Theory, in more depth

The bound that names the three terms

The Ben-David target-error bound makes the three pieces precise. For a hypothesis \(h\), source \(S\), target \(T\):

Ben-David domain-adaptation bound $$\epsilon_T(h)\le \epsilon_S(h) + \tfrac{1}{2}\,\color{#A8432B}{d_{\mathcal{H}\Delta\mathcal{H}}(S,T)} + \lambda$$

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

divergence as domain-discriminator error $$d_{\mathcal{H}\Delta\mathcal{H}}(S,T)\approx 2\big(1-2\,\epsilon_{\mathrm{disc}}\big)$$

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.

Interactive · the divergence dial
divergence d
of maximum 2

AReweighting under covariate shift

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.

BDistribution matching

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.

CParameter transfer and distillation

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.

DDomain generalization

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.

Worked example · the middle groundTrain on three platforms, deploy on a fourth
The setup

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.

What goes wrong naively

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.

The fix: learn what is invariant

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.

How to validate without D

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

From the test rig to the real fleet

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.

Walk the three terms with numbersA vacuous bound, then a usable one
Term one · source error

\(\epsilon_S\) is tiny. A convolutional model on the order-tracked spectrum nails seeded rig faults at over 98 percent. Not the problem.

Term two · divergence, measured

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.

Term three · the joint check

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.

Alignment · collapsing term two

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.

The negative-transfer landmine

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.

The guard

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.

Why matching shapes can backfire

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

Measure the divergence before you trust it

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.

Ways transfer quietly fails
  • Blind marginal alignment. Matching the shape of the data while the labels mean different things in each world can increase target error. Align by class when you can.
  • Ignoring the joint term. If no single model can do well in both worlds, alignment cannot help. A few target labels reveal this early.
  • Over-fine-tuning. Unfreezing too much of a pretrained model on a tiny target set erases the transferable structure you came for.
In agent systems

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

Where to read more

  1. Pan & Yang (2010). A survey on transfer learning. IEEE TKDE. The standard map of the field.
  2. Ben-David, Blitzer, Crammer, Kulesza, Pereira & Vaughan (2010). A theory of learning from different domains. Machine Learning. Source of the three-term bound.
  3. Yosinski, Clune, Bengio & Lipson (2014). How transferable are features in deep neural networks? NeurIPS.
  4. Ganin & Lempitsky (2015). Unsupervised domain adaptation by backpropagation. ICML. Adversarial alignment.
  5. Sun, Feng & Saenko (2016). Return of frustratingly easy domain adaptation (CORAL). AAAI.
  6. Hinton, Vinyals & Dean (2015). Distilling the knowledge in a neural network. NeurIPS workshop.
  7. Arjovsky, Bottou, Gulrajani & Lopez-Paz (2019). Invariant risk minimization. Domain generalization.
  8. Zhao, Combes, Zhang & Gordon (2019). On learning invariant representations for domain adaptation. ICML. Why matching marginals alone can fail.
Companion page · 01 of 02 Knowledge Generalization The same idea with the divergence term removed: succeeding on new examples from the same world.