Representation learning: useful for which task?
表示学习
Compare reconstruction, label information and shifted-data accuracy on a table small enough to inspect completely.
representation-learningStart with the problem
A photograph can vary in lighting, pose, texture and object identity. A representation decides which variations become easy for the next computation to use. Compressing more, reconstructing better and classifying better are different objectives; none automatically certifies the others.
Bengio, Courville and Vincent review how representations expose or entangle explanatory factors. Deep Learning Chapter 15 frames a useful representation in relation to a subsequent task. Our example makes that dependence numerical: a feature with nine times the variance carries no information about the chosen label.
Definitions and derivation
An encoder produces z, and a downstream rule uses z to predict y. One supervised way to learn both is:
Other objectives may reconstruct x, discriminate positive and negative pairs, predict hidden input pieces or fit a density. The choice supplies an inductive bias about which information to retain. Freezing the encoder and fitting a simple probe evaluates accessibility to that probe class; fine-tuning the encoder asks a different question.
Consider all four equally weighted combinations of a large nuisance coordinate and a small label coordinate:
The data are centered. PCA’s first direction is w=(1,0), since variance nine exceeds one. Projection keeps only the nuisance. At each projected value −3 or +3, both labels occur equally often, so even an unrestricted classifier using only that projection cannot exceed 50% on this uniform table. The least-squares linear probe predicts zero; the code resolves a zero prediction as class +1.
A supervised direction proportional to Xᵀy is (0,1), retaining the label exactly. This is a simple learned feature-selection rule for the example, not a full deep encoder. An affine least-squares probe on that representation achieves 100% on the same balanced table. Yet its reconstruction error is worse:
The error sums squared coordinate residuals per row; it is not averaged again over feature dimensions. PCA correctly solves its reconstruction objective. The mistake would be using that objective as a certificate for an unrelated label task. If the target were the sign of coordinate one, the preferred representation would reverse.
Now change the training table so the nuisance coordinate is always three times the label. The covariance direction becomes (3,1)/√10 and yields 100% training accuracy. On the original independent-factor table, its score is dominated by the nuisance sign and accuracy drops to 50%. This constructs a spurious-correlation failure without statistical uncertainty: all four target-domain combinations are explicitly enumerated.
Run the calculation
Complete Python 3.12 / NumPy 1.26.4 program:
import numpy as np
def data():
x=np.array([[-3.,-1],[-3,1],[3,-1],[3,1]])
return x,x[:,1]
def pca_direction(x):
z=np.asarray(x,dtype=float);z=z-z.mean(axis=0);_,_,vt=np.linalg.svd(z,full_matrices=False);w=vt[0];return w if w[np.argmax(np.abs(w))]>=0 else -w
def probe(x,y,w):
x,y,w=np.asarray(x),np.asarray(y),np.asarray(w);design=np.c_[x@w,np.ones(len(x))];coef=np.linalg.lstsq(design,y,rcond=None)[0];return coef
def accuracy(x,y,w,coef):return float(np.mean(np.where(np.c_[x@w,np.ones(len(x))]@coef>=0,1,-1)==y))
def reconstruction_error(x,w):return float(np.mean(np.sum((x-np.outer(x@w,w))**2,axis=1)))
if __name__ == '__main__':
x,y=data();pca=pca_direction(x);supervised=x.T@y;supervised/=np.linalg.norm(supervised)
for name,w in [('PCA',pca),('label covariance',supervised)]:
coef=probe(x,y,w);print(name,'direction',w.round(9).tolist(),'reconstruction MSE',round(reconstruction_error(x,w),9),'balanced-table accuracy',accuracy(x,y,w,coef))
train=np.array([[-3.,-1],[-3,-1],[3,1],[3,1]]);labels=train[:,1];w=train.T@labels;w/=np.linalg.norm(w);coef=probe(train,labels,w)
print('spurious representation',w.round(9).tolist(),'train accuracy',accuracy(train,labels,w,coef),'independent-factor accuracy',accuracy(x,y,w,coef))
Actual output:
PCA direction [1.0, 0.0] reconstruction MSE 1.0 balanced-table accuracy 0.5
label covariance direction [0.0, 1.0] reconstruction MSE 9.0 balanced-table accuracy 1.0
spurious representation [0.948683298, 0.316227766] train accuracy 1.0 independent-factor accuracy 0.5
The first comparison evaluates the complete constructed table, not a held-out performance estimate. The second trains on a confounded source table and evaluates every combination in a different target table. The encoder sees labels only from its declared training table. The target-domain labels are used for scoring, not for refitting the spurious direction.
For a practical evaluation, fit preprocessing and the encoder using permitted training data, fit and select probes under a stated budget, and reserve final test labels for evaluation. Report representation dimension, probe capacity, frozen versus fine-tuned status, data splits and nuisance shifts. A powerful probe can conceal an inconvenient representation; a weak probe may miss useful nonlinear information. Exact SVD and least squares are sufficient for this tiny example and are not neural-network training benchmarks.
When the method fails
No representation is universally sufficient for every downstream task after information is discarded. An invariance helpful for one label may erase a variable needed by another. Retaining all input information is also insufficient to make that information easy to use with a limited decoder.
Learned coordinates need not align with human concepts, and good prediction alone does not establish causal factors. Unlabeled data, augmentations, architecture and supervision each add assumptions. Assess those assumptions against the intended task and deployment changes rather than judging an embedding only by a visually pleasing plot.
Exercises with answers
- Why cannot a nonlinear classifier fix the PCA projection in this example?
Answer 1: Each projected value has equal numbers of both labels; the label information has already been discarded.
- Which direction minimizes reconstruction error?
Answer 2: (1,0), retaining the higher-variance coordinate; this does not make it best for the chosen label.
- Why does the confounded direction fail on independent factors?
Answer 3: It weights the nuisance strongly; its training correlation with the label disappears.
- What does a linear probe measure?
Answer 4: How accessible the target is to an affine linear rule under the chosen fitting protocol, not all possible information in the representation.
Sources and next steps
The representation survey’s physical pages 1 and 4 discuss explanatory factors, generic priors and expressive representations. Deep Learning Chapter 15 opening, printed pages 524–525, relates representation quality to the downstream task and output model. The four-row tradeoff and shifted-table failure are original finite examples. Continue with distributed representations for feature reuse and autoencoders for reconstruction-based learning.
Make a prediction, then check
Why does reconstruction-optimal PCA get only 50% label accuracy here?
Learning objectives
- Separate reconstruction quality from downstream label information.
- Evaluate an explicit nuisance shift without test-label refitting.
Prerequisites & connections
Explore related knowledge →References
- Representation Learning: A Review and New Perspectives — arXiv v3
Yoshua Bengio; Aaron Courville; Pascal Vincent · 2013 - Deep Learning — Chapter 15: Representation Learning
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.
- Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, runnable examples and matching bilingual equations, code and exercises. Not an independent human or second-agent review.
- Four focused CPython 3.12.4 tests passed per chapter, including independent finite differences, literal calculations, recurrence and convolution comparisons, permutation symmetry, closed-form limits and expressive counterexamples. All eight programs use NumPy 1.26.4. CPU teaching calculations, not framework or GPU benchmarks.
- 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.
- Bilingual Matplotlib 3.9.1 SVGs use executed article functions for rigid coordinate updates, per-round routing allocations and reconstruction/label tradeoffs. Figures and sample data are hash-bound. Displacements are unscaled, rounds are not training steps, and diagnostic-table accuracy is not a held-out estimate.
Source locations checked:
- Representation Learning: A Review and New Perspectives — arXiv v3 · Physical pages 1 and 4: explanatory factors, generic representation priors and expressiveness discussion.
- Deep Learning — Chapter 15: Representation Learning · Chapter 15 opening, printed pages 524–525: useful representations depend on subsequent task, decoder and learning protocol.
Related topics