AI Wiki中文/EN

Transfer learning: what a frozen feature can lose

迁移学习

Fit a source representation, compare frozen and fine-tuned targets, and expose an exact information bottleneck.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A useful source feature may discard the target’s answer

A model trained to predict an object’s width may learn to ignore height. That representation is helpful for another width-related task, but freezing it can make a height-related task impossible, no matter how well a new output head is trained.

Transfer learning reuses knowledge from a source for a target. Reuse can concern examples, representations, parameters or relations; it is broader than downloading a pretrained neural network. Pan and Yang’s survey, Section 2, separates domain/task definitions and source-to-target roles. This chapter focuses on frozen features and parameter initialization. Read linear regression and gradient descent first.

Freezing changes the set of functions you can fit

Take a two-dimensional input x and a source-trained vector u. A frozen scalar representation followed by a trainable linear head has the form:

z=u⊤x,y^=az=(au)⊤x.z=u^\top x,\qquad \widehat y=a z=(a u)^\top x.

Only a changes. The resulting weight vector must remain in the one-dimensional span of u. Fine-tuning a full weight vector w instead permits movement outside that span. The two procedures have different hypothesis classes in this example; a comparison should acknowledge that difference.

Use all four points x∈{−1,1}2x\in\{-1,1\}^2 with equal weight. Train the source task y_S=x₁ by least squares. It learns u=(1,0), so the transferred feature is z=x₁. Now set the target to y_T=x₂. The input coordinates have zero mean, unit variance and zero cross moment. Consequently:

E[(ax1−x2)2]=a2+1,a∗=0,Rfrozen=1.\mathbb E[(a x_1-x_2)^2]=a^2+1, \qquad a^*=0,\qquad R_{\mathrm{frozen}}=1.

The best frozen head predicts zero. It cannot recover x₂ because the representation discarded it. Using the unadapted source prediction x₁ is even worse, with target MSE 2. A constant-zero baseline also has MSE 1. These exact calculations concern the uniform four-point distribution, not an unseen real dataset.

For an aligned target y_T=2x₁, the frozen feature is sufficient. One labeled head-training example at x=(1,1),y=2 determines a=2 and predicts all four points correctly. Without that representation constraint, one equation cannot uniquely determine both coefficients of a general two-dimensional linear model.

Fit the source, freeze a head, then update both weights

This complete Python 3.12 program actually fits the source weights by a two-by-two normal equation, fits the frozen head, and performs gradient updates for the target. It also runs a target-only initialization under the same target data and update budget.

from fractions import Fraction as F
from itertools import product


def data(inputs, targets):
    inputs=[list(row) for row in inputs];targets=list(targets)
    if not 1<=len(inputs)<=32 or len(targets)!=len(inputs) or any(len(row)!=2 for row in inputs):
        raise ValueError('one to32 paired two-dimensional examples required')
    if any(type(x) is not int or x not in (-1,1) for row in inputs for x in row):
        raise ValueError('teaching inputs must have two coordinates in{-1,1}')
    if any(type(y) not in (int,F) or abs(y)>1000000 for y in targets):
        raise ValueError('bounded rational targets required')
    return inputs,list(map(F,targets))


def weights(values):
    values=list(values)
    if len(values)!=2 or any(type(v) not in (int,F) or abs(v)>1000000 for v in values):
        raise ValueError('two bounded rational weights required')
    return list(map(F,values))


def fit_linear(inputs, targets):
    x,y=data(inputs,targets);a=sum(row[0]**2 for row in x);b=sum(row[0]*row[1] for row in x);c=sum(row[1]**2 for row in x)
    d=sum(row[0]*v for row,v in zip(x,y));e=sum(row[1]*v for row,v in zip(x,y));det=a*c-b*b
    if det==0:raise ValueError('two weights are not uniquely identifiable from these inputs')
    return ((c*d-b*e)/det,(a*e-b*d)/det)


def frozen_head(representation, inputs, targets):
    u=weights(representation);x,y=data(inputs,targets);z=[sum(v*t for v,t in zip(u,row)) for row in x]
    denominator=sum(v*v for v in z)
    if denominator==0:raise ValueError('frozen feature is zero on every training input')
    head=sum(v*t for v,t in zip(z,y))/denominator
    return tuple(head*v for v in u)


def fine_tune(inputs, targets, start, steps=20, rate=F(1,2)):
    x,y=data(inputs,targets);w=weights(start)
    if type(steps) is not int or not 0<=steps<=100 or type(rate) not in (int,F) or not 0<rate<=F(1,2):
        raise ValueError('zero to100 steps and rational rate in(0,1/2] required')
    for _ in range(steps):
        residual=[sum(v*t for v,t in zip(w,row))-value for row,value in zip(x,y)]
        gradient=[sum(row[j]*r for row,r in zip(x,residual))/len(x) for j in range(2)]
        w=[v-F(rate)*g for v,g in zip(w,gradient)]
    return tuple(w)


def mse(inputs, targets, parameters):
    x,y=data(inputs,targets);w=weights(parameters)
    return sum((sum(v*t for v,t in zip(w,row))-value)**2 for row,value in zip(x,y))/len(x)


if __name__=='__main__':
    x=list(product((-1,1),repeat=2));source_y=[row[0] for row in x];target_y=[row[1] for row in x]
    source=fit_linear(x,source_y);frozen=frozen_head(source,x,target_y)
    tuned=fine_tune(x,target_y,source);scratch=fine_tune(x,target_y,(0,0))
    print('learned source representation:',*[str(v) for v in source])
    for name,w in [('unadapted source',source),('constant-zero baseline',(0,0)),('frozen feature with fitted head',frozen),('fine-tuned20 steps',tuned),('target-only20 steps',scratch)]:
        print(name,'target MSE:',mse(x,target_y,w))
    aligned=frozen_head(source,[(1,1)],[2])
    print('aligned target from one head-training example, four-point MSE:',mse(x,[2*row[0] for row in x],aligned))

Output:

learned source representation: 1 0
unadapted source target MSE: 2
constant-zero baseline target MSE: 1
frozen feature with fitted head target MSE: 1
fine-tuned20 steps target MSE: 1/549755813888
target-only20 steps target MSE: 1/1099511627776
aligned target from one head-training example, four-point MSE: 0

All arithmetic is rational. The teaching input contract restricts both coordinates to−1 or 1, with at most 32 examples. That bound gives a squared-loss Hessian spectral norm at most 2, so rates up to 1/2 are safe for nonincreasing gradient-descent objectives. The source least-squares solver rejects singular designs; it does not invent a unique fit from insufficient equations.

For the uniform four-point target, the feature second-moment matrix is I. Gradient descent on half MSE at rate 1/2, initialized at the source(1,0), therefore satisfies:

w(t+1)=w(t)−12(w(t)−(0,1)),w(t)=(2−t,1−2−t),Rt=21−2t.w^{(t+1)}=w^{(t)}-\frac12(w^{(t)}-(0,1)),\qquad w^{(t)}=(2^{-t},1-2^{-t}),\qquad R_t=2^{1-2t}.

After 20 steps, MSE is 1/549755813888. Target-only initialization at zero has MSE 1/1099511627776 after the same 20 steps: transfer is not faster on this orthogonal target. In this convex problem, source initialization changes the optimization path, not the unique optimum when the design has full rank.

Normal-equation fitting and each gradient step cost O(n) for the fixed two-dimensional model. Rational bit costs grow with update count; the implementation caps it at 100. These costs do not describe training a large pretrained network. The experiment illustrates a geometric mechanism, not a neural transfer benchmark.

Successful pretraining does not certify useful transfer

Yosinski and colleagues,2014, Sections 1–2, distinguish frozen and fine-tuned features and design transfer/control experiments on ImageNet task splits. Their neural-network observations concern that architecture, data and training setup. Our discarded-coordinate example is an original linear construction, not a reproduction of their results.

Freezing reduces trainable capacity and can preserve useful source structure. It can also lock in an information bottleneck. Fine-tuning can adapt features but may overfit a small target dataset, forget source capabilities or depend strongly on optimization settings. Neither option is universally preferable.

Separate source training data, target training/validation data and final target evaluation. If source data overlap the target test set, apparent transfer may be contamination. Compare against target-only training, a simple baseline, frozen features and an appropriate fine-tuning budget. Include source pretraining cost when the intended comparison requires paying it; disclose when a reusable model makes it a sunk cost.

What can the frozen head still express?

  1. Which target information is lost when u=(1,0)?

Answer 1: The second coordinate x₂ is not represented by z=x₁.

  1. What is the minimum frozen-head MSE for target x₂?

Answer 2: One, attained at a=0 under the uniform four-point distribution.

  1. Does fine-tuning outperform target-only initialization at the same 20-step budget here?

Answer 3: No. Both approach the optimum, but target-only initialization has half the MSE in this example.

  1. Why can one example fit the aligned target head?

Answer 4: The useful frozen representation leaves only one unknown coefficient; the example has nonzero feature value.

Vary task alignment before scaling the model

Project: set the target to y_T=αx₁+βx₂. Derive the best frozen-head riskβ², then verify it across several coefficients. Compare target-only and source-initialized optimization with matched data and steps. Keep the source representation fixed during frozen-head experiments.

For a neural extension, vary which layers are frozen and track target validation performance, training cost and any required source retention. Multi-task learning optimizes several tasks together; domain adaptation adds explicit concerns about changing source and target distributions.

Make a prediction, then check

Why can the frozen head not recover the second coordinate?

Choose one answer

Learning objectives

  • Explain the hypothesis-class restriction caused by freezing.
  • Compare source, frozen-head, fine-tuned and target-only baselines.
  • Separate task alignment, optimization path and target evaluation.

Prerequisites & connections

Explore related knowledge →

References

  1. A Survey on Transfer Learning — accepted author manuscript
    Sinno Jialin Pan; Qiang Yang
  2. How transferable are features in deep neural networks? — arXiv v1
    Jason Yosinski; Jeff Clune; Yoshua Bengio; Hod Lipson · 2014

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.

  • Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
  • Four focused CPython3.12.4 tests passed per chapter. Exact rational metrics, four-outcome task risks, source/frozen/gradient fits and shifted-domain risks are checked against literal or analytic references. No external runtime dependencies.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.