🌏 中文版
Video status: Videos included. This article is written from the official MOOC handout 213_handout.pdf and transcripts of the four official videos, with formulas following the handout. The transcripts are machine transcripts made for this article (Whisper), not official captions, and no human has proofread them. The videos are taught in Mandarin; the slides are in English. Each section opens with its official video and the approximate time ranges. Page numbers refer to the number at the lower right of each slide (0/24 to 24/24), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.
This is Techniques Lecture 13 in Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques. The Roadmap on page 1 of the handout divides Techniques into three ways of handling features, and this lecture belongs to the third, Distilling Implicit Features: Extraction Models, where the model extracts hidden features from the data by itself. The previous lecture, Techniques Lecture 12: Neural Networks, takes up one line on that page: automatic pattern feature extraction from layers of neurons, with backprop computing the gradient for gradient descent or stochastic gradient descent. This lecture asks what happens when the number of layers grows.
The recordings were uploaded in 2016, and page 3 of the handout says deep learning is "gaining attention in recent years". So the lecture is about the methods of that time: layer-wise pre-training and the autoencoder. Understanding why pre-training was needed then is more useful than memorizing the steps. For the training techniques common today, Lin added two slide decks in Fall 2024, which this series covers in Techniques Lecture 16: Finale.
There are three prerequisites. The first is the network notation of the previous lecture (--…-, , ) and backprop. The second is the causes of overfitting from Foundations Lecture 13: Hazard of Overfitting and weight decay from Foundations Lecture 14: Regularization. The third is linear algebra: orthogonal matrices and the eigen-decomposition of a symmetric matrix. The last section uses a Lagrange multiplier once, as in Techniques Lecture 2: Dual SVM.
After reading, you should be able to say what a deep network adds over a shallow one and which four things make it hard; walk through layer-wise pre-training and say, at each step, which data trains which autoencoder and which weights are kept; explain why adding noise counts as regularization; and start from and derive for yourself that the optimal consists of the top few eigenvectors of , then compute it by hand for a small data set.
What a deeper network adds, and where it gets hard
(In the video, 00:17–02:27 reviews the previous lecture and raises the question of structure, 02:27–05:55 compares shallow and deep, 05:55–11:42 uses handwritten digits to explain what each layer means, 11:42–18:36 covers the four challenges and the matching techniques, 18:36–20:53 is the two-step framework, and the rest is Fun Time.)
You have to decide the structure yourself
Page 2 of the handout redraws the network of the previous lecture, reminds us that each layer is a pattern feature extracted from data, and then asks: how many neurons? How many layers? More generally, what structure? In the lecture, Lin adds that structure also includes which neuron connects to which, and whether connections may skip layers.
The handout answers in two directions: subjectively, your design; objectively, validation, maybe. The lecture has a remark on each. "Your design" is like an electrical engineering student designing a circuit: put this component here and that one there, wire them up, and see whether it works. Validation treats the structure as a kind of parameter, so every model selection method from Foundations Lecture 15: Validation applies; the trouble is that there are too many possible structures. The handout concludes that structural decisions are the key issue for applying NNet.
Shallow versus deep
Page 3 starts with definitions: few hidden layers is shallow, many layers is deep. In the lecture, Lin says a shallow network produces its output after only one or two layers, while a deep one goes through many steps before reaching a result. The slide puts the two side by side; the circles and crosses in parentheses are the handout's own marks:
| Shallow NNet | Deep NNet | |
|---|---|---|
| Training | more efficient to train (○) | challenging to train (×) |
| Structural decisions | simpler (○) | sophisticated (×) |
| Power | theoretically powerful enough (○) | 'arbitrarily' powerful (○) |
| Meaning | not listed | more 'meaningful'? |
The lecture goes through the cells one at a time. A shallow network has few layers, so both the forward pass for the output and the backward pass for δ are faster, and the only decision is how many neurons to put in those few layers. "Theoretically powerful enough" refers to a result mentioned in the previous lecture: with enough neurons, a network can approximate any function, so a few layers with enough neurons each can still do complicated things. In the deep column, the first two cells are the same trade-offs reversed. On the "'arbitrarily' powerful" cell, Lin says it is really about the same as the shallow case: enough neurons and weights will do it.
So in terms of power, deep networks do not win. Their real selling point is the last cell, which the handout itself marks with a question mark and then spends a whole page on.
Each layer does a little: the handwritten digit example
The figure on page 4 is a small network that recognizes the handwritten digits 1 and 5. From bottom to top it shows:
- At the bottom are the inputs, two digits, 1 and 5, drawn in pixels.
- The first layer has six nodes, to , each drawn as a short stroke: is a small slanted stroke at the upper left, is a vertical stroke in the middle, is a horizontal stroke at the bottom, is a corner at the upper left, is a bend in the middle, and is an arc at the lower right.
- The second layer has two nodes: answers "is it a '1'?" and answers "is it a '5'?". Blue lines are positive weights and red lines are negative weights. has blue lines to , , and red lines to , , ; has blue lines to , , , and red lines to , .
- The output node at the top has a blue line to and a red line to .
In the lecture, Lin puts it this way: the neuron that recognizes 1 wants the previous layer to report that these three parts are present and the other three are absent, which the right weights can express; 5 needs the curved parts, plus the horizontal stroke at the bottom.
The figure shows only signs, not values. The numbers below are made up for this article, not from the slides, to walk through the figure once. Let mean the image has stroke and mean it does not; give blue lines weight and red lines weight , with no constant term.
| Input | Score of | Score of | Score of the output node, | |
|---|---|---|---|---|
| A standard 1 | ||||
| A standard 5 | ||||
| A 1 missing the upper-left stroke |
Take the third row: the score of is . With one stroke missing, the score drops from 6 to 4 but stays positive, so the answer is still 1. This is what Lin describes in the lecture: when the writing is a bit sloppy and some features are unclear, the digit is still mostly recognizable.
The handout states the point of this example in two lines. The first is 'less burden' for each layer, with features going from simple to complex. The lecture's analogy is not trying to reach the top in one step: separating 1 from 5 straight from a pile of pixels is hard, but if the first layer only has to find short strokes in the pixels and later layers combine short strokes into slightly more complex ones, the work between layers becomes simple. With a single hidden layer, that one layer has to do something very complicated.
The second line is that deep networks are natural for difficult learning tasks with raw features. In the lecture, Lin explains that the raw features of an image are pixels and those of speech are sound waves; a single feature has very limited physical meaning, people have no good way to design a feature transform, and the only option is to let the model learn it layer by layer. The page concludes that deep networks were popular at the time in areas like vision and speech.
The lecture adds one caveat: this figure is actually still shallow, with only two layers. It is only there to show that each layer can carry a different physical meaning.
Four challenges and the matching techniques
Page 5 lists four challenges of deep learning, each paired with a kind of remedy from that time:
| Challenge | Remedy | Example in the handout |
|---|---|---|
| Difficult structural decisions | Put in what you know about the problem (domain knowledge) | convolutional NNet for images |
| High model complexity | No big worries if the data is big enough; also regularization towards noise tolerance | dropout (tolerant when the network is corrupted), denoising (tolerant when the input is corrupted) |
| Hard optimization problem | Careful initialization to avoid a bad local minimum, called pre-training | — |
| Huge computational complexity, worse with big data | Novel hardware and architecture | mini-batch with GPU |
The lecture says a little more about each row:
- Structure. The idea of the convolutional NNet is that the pixels of an image have positions relative to each other. So when designing the connections, let neighboring pixels connect to the same neuron in the next layer, and do not connect pixels that are far apart at all. This amounts to deciding in advance that some weights do not exist, so each neuron handles only nearby pixels.
- Complexity. Vision and speech usually come with a lot of data, enough to support the model's complexity, so the pressure moves to computation instead. The lecture does not go into dropout; Lin only says it simulates some neurons in the network breaking down, in the hope that the final result is still computed well. Denoising simulates the input breaking down, and the section on why adding noise counts as regularization covers it.
- Optimization. The previous lecture said neural networks easily get stuck at local optima, and with more layers and neurons there are more such points. Gradient descent is sensitive to its starting point, so many methods choose the starting point carefully instead of at random.
- Computation. In the lecture, Lin says this is where things differ a lot from thirty years earlier: a GPU has many computing units and can compute the gradients in a mini-batch in parallel.
The footer is Lin's personal opinion (the slide says IMHO): careful regularization and initialization are key techniques. In the lecture, Lin calls these the two most important breakthroughs that let networks go deeper and deeper. The remaining three sections of the lecture therefore cover only these two: the simplest pre-training technique, along with one regularization technique.
A two-step deep learning framework
Page 6 gives a simple framework, which the handout calls Simple Deep Learning:
- For , pre-train assuming fixed.
- Train with backprop on the pre-trained NNet to fine-tune all .
The page has four small figures, (a) to (d), each a network with four rows of nodes and three layers of weights, input at the bottom. In (a) only the bottom layer of weights is blue, meaning it is being pre-trained, and the rest are gray dashed lines; in (b) the bottom layer has turned black (fixed) and the second layer is blue; in (c) it is the third layer's turn; in (d) everything is black and step 2 can begin.
In the lecture, Lin gives the reasoning: deciding all the weights at once is too hard, so do it one layer at a time. Step 1 only decides the starting point, so it can be quick and need not be very accurate; once the network is in a good place, backprop can always fine-tune it to do better on the actual problem.
The framework does not yet say what "pre-train" in step 1 trains. That is the question the autoencoder answers.
Fun Time: what the first layer extracts
Question (page 7): For a deep NNet for written character recognition from raw pixels, which type of features are more likely extracted after the first hidden layer?
- pixels
- strokes
- parts
- digits
Answer: 2. The handout's reason: simple strokes are likely the 'next-level' features that can be extracted from raw pixels. Pixels are the input itself and need no extraction, so choice 1 is wrong. Parts are made of several strokes, and digits are made of parts, which only later layers and the output can produce; in the lecture, Lin says the first layer will not give anything too complicated, nor tell us directly how to classify in the end. The figure on page 4 follows exactly this order: pixels → strokes → 1 or 5.
Where pre-trained weights should head: an encoding that decodes back to the input
(In the video, 00:00–03:22 discusses information-preserving encoding, 03:22–05:30 is the autoencoder network, 05:30–09:40 explains what approximating the identity function is good for, 09:40–12:44 is the basic autoencoder, 12:44–14:39 puts it into pre-training, and the rest is Fun Time.)
Good weights are an information-preserving encoding
Page 8 first asks what weights are. Weights determine a feature transform, or in other words an encoding: they turn the data into another representation.
When one layer is being pre-trained, the later layers are not decided yet, and nobody knows how these weights will later be fine-tuned or used. From this the lecture derives a criterion: since we do not know what the weights will be used for, this layer should at least not lose information. After the transform, later layers should not find the data scrambled and unusable; whatever information the original data carries, the new representation should carry something similar. The handout writes it as information-preserving encoding: the next layer holds the same info with a different representation.
How do we judge whether information is preserved? The handout's definition is: decode accurately after encoding. The lecture explains with the stroke example. Once the pixels of the digit 1 are turned into "which of these strokes are present", knowing that it has , , is enough to stack those strokes and rebuild roughly what that 1 looks like. The numbers Lin gives: suppose there were a thousand pixels to begin with, and after turning them into six features we can still turn them back into a thousand pixels; then no information loss is visible, only a change of representation.
So the direction of pre-training is settled: move the weights towards an information-preserving encoding.
Autoencoder: a network whose output should look like its input
Page 9 turns this idea into a neural network. The inputs are (plus ), the middle layer has neurons (plus the constant ), and the output layer has linear nodes, with output aiming to be close to . The handout's definitions:
- autoencoder: a —— NNet with goal , that is, learning to approximate the identity function.
- are the encoding weights, and are the decoding weights.
In the lecture, Lin points out one difference from the previous lecture's network: there is no longer a single output but of them, one for each dimension of the input.
Then comes a natural doubt, which the handout writes in the footer: the identity function takes one line of code, so why go to the trouble of approximating it?
What approximating the identity function is good for
Page 10 answers. The premise: if is achieved using some hidden structures on the observed data , then the learned structure is itself useful.
- For supervised learning: the hidden structure can be used as a reasonable transform . The handout calls this learning an 'informative' representation of data. In the lecture, Lin says the encoding half of the weights is this transform; it is a decent starting point that can be fine-tuned later, which makes it suitable for pre-training.
- For unsupervised learning: in density estimation, places where match the structure and have larger density; in outlier detection, those where are the outliers. The handout calls this learning a 'typical' representation of data. The lecture's explanation: where data is dense, the encoder has seen enough and does better; on points that do not fit in, the encoder does worse.
The lecture sums the page up in one line: approximating the identity function is only the means, and what we actually want is the representation in the middle layer. The handout's wording is representation-learning through approximating identity function.
One addition in this article, to help see why the middle layer learns anything. If , the middle layer has enough room to carry the input across unchanged, and approximating the identity function needs no structure at all. When , numbers have to squeeze into numbers and then be restored, and that can only go well if the data itself has regularity (for example, the pixels of a digit are really made up of a few kinds of strokes).
The basic autoencoder
Page 11 gives the formal definition. The basic autoencoder is a —— NNet whose error function for each example is
The handout lists four properties:
- Backprop easily applies. It has a single hidden layer, so it is shallow and easy to train. In the lecture, Lin says it is at least much easier than a very deep network.
- Usually . The result is a compressed representation.
- The data is . Both input and target are and no labels are used, so it is often categorized as an unsupervised learning technique. The lecture describes this as covering up the labels for now; later, to separate 1 from 5, backprop adjusts the whole network.
- Sometimes constrain as regularization. Encoding and decoding share one set of weights, which cuts the number of weights roughly in half. The cost is a more complicated gradient calculation; in the lecture, Lin says the effect of this constraint has to be accounted for.
The footer states its use in this lecture: in basic deep learning, once the autoencoder is trained, are taken as the pre-trained weights. An addition in this article: in other words, the decoding half is needed only while training the autoencoder and is not used after that.
Worked example: a 2-1-2 autoencoder
The following is an example made up for this article, not from the slides. The data is four two-dimensional points with no labels:
The autoencoder is 2-1-2: two inputs, one neuron, two linear outputs, with and . The number of weights is , of which 3 encode and 4 decode. Suppose training produces the following weights (this article simply states them; no training was actually run):
- Encoding: , , .
- Decoding: , .
One forward pass for :
- Encode: , and the middle layer outputs . This single number is the new representation of .
- Decode: .
- Error: .
Results for six points (the first four are the training data, the last two are new points):
| Encoded value | Error | ||
|---|---|---|---|
Three things can be read off this table.
First, compression has a cost. and are encoded to the same number and cannot be told apart after decoding. One number cannot hold all the information in two, and these weights choose to keep the sum of the two coordinates and let go of their difference. The four points differ a lot along the coordinate-sum direction () and little along the coordinate-difference direction (), so this choice gives a small error. The section on the linear autoencoder will compute that, with a single number and a linear decoder, an average of 0.5 over the four points is already the smallest achievable error.
Second, the encoding half is the feature transform . What pre-training keeps is the three weights .
Third, the size of the error can tell whether a point is typical, which matches the outlier detection on page 10. lies along the main direction of the data and has an error of almost 0; is perpendicular to the trend of the four examples and has an error of 8, which is 16 times that of the training data.
Pre-training with autoencoders
Page 12 fills the autoencoder into the earlier two-step framework, and the handout calls the result Deep Learning with Autoencoders. Step 1 gains a line:
- For , pre-train assuming fixed, by training a basic autoencoder on with .
- Train with backprop on the pre-trained NNet to fine-tune all .
is the output of example at layer , and is the raw input. In the lecture, Lin explains that the number of neurons in the middle of the autoencoder is set by the number of neurons in the network's next layer; training yields a set of starting weights, which are then fixed before moving on to the next layer.
Let us walk through a concrete network. The network size below is made up for this article: to tell whether a 16×16 handwritten digit image is a 1 or a 5, with 256 input pixels, the network is 256-64-16-6-1, and there are images.
| Step | Training data | Autoencoder | Encoding weights kept | Decoding weights discarded |
|---|---|---|---|---|
| Raw pixels (256 dimensions) | 256-64-256 | , used as | ||
| Layer 1 outputs (64 dimensions) | 64-16-64 | , used as | ||
| Layer 2 outputs (16 dimensions) | 16-6-16 | , used as | ||
| Layer 3 outputs (6 dimensions) | 6-1-6 | , used as |
After each layer, all images have to be passed through the weights just fixed to produce the training data for the next step. After the four steps, all weights of the network have starting values, and only then are the labels brought out to fine-tune every weight with backprop. The first four steps never use the labels.
The footer notes that many successful pre-training techniques take 'fancier' autoencoders with different architectures and regularization schemes. In the lecture, Lin says these methods are much alike, differing in some extra regularization or in how things are connected.
Fun Time: how long pre-training takes
Question (page 13): Suppose training a -- autoencoder with backprop takes approximately seconds. Then, what is the total number of seconds needed for pre-training a ----1 deep NNet?
Answer: 3. The handout's solution: each represents the time for pre-training with one autoencoder to determine one layer of the weights. Four layers of weights need four autoencoders, trained one after another, so the times add. The last term is , for the weights of the output layer.
Choice 1 treats the time of each autoencoder as depending on the size of only one side; choices 2 and 4 multiply the times, but the four autoencoders are trained in sequence, not as nested loops.
A check from this article: with the earlier 256-64-16-6-1, choice 3 gives . The first term alone is 94%, so almost all the pre-training time goes to the widest layer. Choice 2 would give , off by a factor of nearly 90.
Why adding noise counts as regularization: the denoising autoencoder
(In the video, 00:00–01:32 looks back at the regularization already learned, 01:32–02:27 reviews the causes of overfitting, 02:27–07:19 is the idea of adding noise and the denoising autoencoder, 07:19–08:05 files it under hints, and the rest is Fun Time.)
The regularization tools we already have
Pre-training deals with initialization; this section turns to regularization. Page 14 shows the network figure once more, with "watch out for overfitting" written beneath it: with this many weights and neurons, model complexity is high and regularization is needed. The handout lists three kinds we already know:
- Structural decisions/constraints. The lecture's example is the convolutional NNet: having fewer connections is itself a constraint.
- Weight decay or weight elimination regularizers. From the previous lecture.
- Early stopping. Also from the previous lecture: backprop does not have to run to the end, and stopping partway may be better.
The handout says another regularization technique comes next.
Noise is a cause of overfitting
Page 15 returns to the figure from Foundations Lecture 13: Hazard of Overfitting: the horizontal axis is the number of data points (the ticks run from 80 to 120), the vertical axis is the stochastic noise level (0 to 2), and color shows the amount of overfitting, redder being worse. The upper left, with little data and much noise, is solid dark red; the lower right, with much data and little noise, is blue. Beside the figure the reasons are arranged in three lines:
| Situation | Overfitting |
|---|---|
| Data size goes down | gets worse |
| Noise goes up | gets worse |
| Excessive power | gets worse |
The lecture's inference: if the model and the data size are already fixed, the only thing left to deal with is the noise.
Adding noise to the data
Page 16 first lists the direct possibility: data cleaning/pruning, mentioned in Foundations Lecture 13. Then comes what the handout itself calls a "wild" possibility: adding noise to data. In the lecture, Lin voices the students' doubt for them: there is already too much noise in the data, so why add more?
The idea starts from what a good autoencoder should be like. The handout writes: a robust autoencoder should not only let but also allow even when is slightly different from . The lecture's example is a handwritten digit: if the same character is written a bit uglier or more crooked, or the paper is a bit dirty, the decoded result should still be about the same as the original clean character. An encoder that takes in dirty and puts out dirty, or even dirtier, is not much use.
The method leaves the network alone and changes only the data fed in. The handout's definition:
- denoising autoencoder: run the basic autoencoder with the data
The input is , with artificial noise added, and the target is still the clean . The handout then lists three points:
- In deep learning, it is often used instead of the basic autoencoder.
- It is useful for data/image processing: is a denoised version of . The lecture's example is a scanned image that carries a little noise.
- Its effect is to 'constrain/regularize' towards a noise-tolerant, denoising function.
Why does this count as regularization? The lecture's analogy is telling the encoder: child, the world is messy, but I am telling you what the right answer is, and however messy the input, there is a lamp pointing the right way. Feeding noisy inputs with clean targets tells the algorithm what property we want to have and steers it that way, which is what regularization does.
The footer generalizes the idea: artificial noise/hint as regularization, practically also useful for other NNet and models. In the lecture, Lin recalls that Foundations called adding artificially designed data a hint, which likewise tells the machine what kind of data to handle better.
Worked example: in the simplest model, noise becomes a penalty on the weight
The following is an example made up for this article, not from the slides. It handles only the simplest case, to make clear how "adding noise" relates to the weight decay of Foundations Lecture 14.
The data is four one-dimensional numbers, . The model is a one-dimensional linear autoencoder , where is the product of the encoding weight and the decoding weight. On clean data, makes the error 0.
Now give every two noisy versions, and , for eight training examples in all:
Solving directly. We minimize . Differentiating with respect to and setting the result to 0 gives . The numerator is and the denominator is , so
Seeing the penalty term. Put the two versions of one together. Writing the noise as , the error is
Averaging over and , the middle term cancels and is 1 both times. Averaging again over the four , the mean of is :
The first term is the without noise. The second is the square of times the variance of the noise (here 1); viewing as a weight, it has the same form as the of weight decay, with the noise variance playing the role of . Differentiating with respect to : , which gives , in agreement with the direct solution.
| Error on clean data, | Term from the noise, | Sum | |
|---|---|---|---|
What this result means. With noise added, the optimal shrinks from 1 to : the model learns that the input has been inflated by noise and the output should pull back a little. Its error on clean data goes from 0 to 0.204, the usual price of regularization, a slightly worse in exchange for a less sensitive to perturbations of the input. The stronger the noise, the more shrinks in this example.
This identity was derived under the conditions of this example: the model is linear, the error is squared error, and the noise is symmetric in sign so the cross term cancels. It is not a conclusion of the handout and cannot be carried over directly to a network with . The handout only says the effect of denoising is to constrain towards noise tolerance.
Fun Time: which one is not regularization
Question (page 17): Which of the following cannot be viewed as a regularization technique?
- hint the model with artificially-generated noisy data
- stop gradient descent early
- add a weight elimination regularizer
- all the above are regularization techniques
Answer: 4. The handout's solution: choice 1 is our new friend for regularization, while choices 2 and 3 are old friends. Choice 1 is the denoising of this section; choice 2 is early stopping and choice 3 is weight elimination, both from the previous lecture. All three are regularization, and none of them fits the "cannot be viewed as" the question asks for, so the answer is 4.
In the lecture, Lin reads choice 4 aloud as "none of the above", which means the same thing: none of the first three is the one the question is looking for. On the handout, choice 4 reads "all the above are regularization techniques".
Making the autoencoder linear: the optimal solution is the top eigenvectors of XᵀX
(In the video, 00:01–05:58 writes out the linear autoencoder hypothesis, 05:58–07:47 is the error function, 07:47–14:11 does the eigen-decomposition and gives its geometric meaning, 14:11–18:15 finds the optimal Γ, 18:15–24:48 finds the optimal V, 24:48–28:50 is PCA, 28:50–29:38 is Fun Time, and the rest summarizes the whole lecture.)
The linear autoencoder hypothesis
The autoencoder so far has in the middle and is nonlinear. Page 18 goes back to ask about the linear version, with the reasons written on the page: linear may be more efficient and overfit less, and this course has always been linear first. In the lecture, Lin explains why it was skipped earlier: every layer in deep learning has to make a nonlinear transform anyway, so the nonlinear autoencoder is more useful in that architecture; the linear version can be used to process data and need not be used in deep learning.
Take out , and output is just two layers of weights multiplied together. The handout adds three special conditions:
- Exclude . This makes the range of the same as the range of . The lecture's reason: if the input had a dimension 0, the output would also need a dimension 0 to compare against the constant, which makes little sense.
- Constrain . This is the regularization mentioned on the basic autoencoder page, with encoding and decoding sharing weights. Collect these weights into a matrix .
- Assume . This ensures a non-trivial solution.
Under these conditions, the handout writes the hypothesis for the -th component as
On the slide the outer sum runs from to ; in the lecture, Lin says ranges from 1 to , and , of size , only has room for these columns, so the matrix form below has no term.
Read it as matrix operations. Row , column of is , so the inner parenthesis is component of the vector ; this is the encoding, and the result has dimensions. The outer is component after multiplying by again; this is the decoding, and the result is back in dimensions. The handout's conclusion:
An addition in this article, on the reason for the third condition. If , let be whichever orthogonal matrix you like (the identity matrix, for example), and then , , and the error is 0, yet no structure has been learned. In the lecture, Lin only says this case has a very trivial solution, which is not what we want.
The error function is a fourth-order polynomial in the weights
Page 19 writes down the quantity to minimize. The error is still squared error, averaged over all the data:
A linear model with squared error has a one-step analytic solution in Foundations Lecture 9: Linear Regression. Can there be one here too? Under the formula the handout writes only one remark: this is a 4-th order polynomial of . In the lecture, Lin says that is why it does not look easy at first sight.
An addition in this article: write the fourth-order polynomial out for . Then has a single column, written as the vector , and :
The three terms are of order zero, two, and four in . Differentiating with respect to gives cubic equations, without the luck of linear regression, where solving one linear system finishes the job. The handout's route is a change of variables. In the lecture, Lin says the problem still has an analytic solution; it is just not easy to see at a glance.
A change of variables: eigen-decompose WWᵀ
Here the handout writes "be brave", because linear algebra comes next. Look at the formula for : appears only in the form . In the lecture, Lin points out that is a positive semi-definite matrix (it is also symmetric), so it can be eigen-decomposed:
The handout lists the properties of the two matrices:
- is a orthogonal matrix, . Each of its columns has length 1, and the columns are perpendicular to one another.
- is a diagonal matrix with at most non-zero values on its diagonal.
The second point comes from rank. has only columns, and is always a linear combination of those columns, so the rank of is at most , and there are at most non-zero eigenvalues. The numbers in the lecture are and : at most 50 entries on the diagonal are non-zero, and the other 150 must be 0. The original restriction on the size of thus turns into a restriction on .
So splits into three actions, which the handout explains one by one:
- : a change of orthonormal basis, geometrically a rotation or reflection. In the lecture, Lin stresses that a vector rotated around in space or reflected in a mirror keeps its length.
- : set at least components to 0, and scale each of the others.
- : reconstruct by coefficients and basis, that is, rotate back to the original coordinates.
The original can be written in the same form: , rotate, do nothing, rotate back. The two terms subtracted in then differ only in whether the middle is or . The problem changes from "find " to "find and ", and the handout does it in two steps, first and second.
The optimal Γ: put d̃ ones on the diagonal
The problem on page 20 is
Treat as fixed for now and look only at . Factoring out what the two terms share, the inside of the norm is . The leading is the back-rotation and does not change length: for any vector , . The slide therefore crosses out that leading , leaving
The handout's wording: we want many 0 within . In the lecture, Lin says the more zeros the better, and the only things we can move are the diagonal values of ; to get a 0 on the diagonal of , put a 1 on the diagonal of , and at most of them can be placed.
This article writes that sentence as a formula. Component of is , and is a diagonal matrix that multiplies component by . So
Each controls its own term. If has to be 0, that term is ; if it may be non-zero, taking makes the term 0, and nothing is smaller than that. At most of them may be non-zero, so the optimal has diagonal components equal to 1 and the other components 0. The handout then says that, without loss of generality, the ones can be placed first:
This ordering is allowed because is not decided yet, and which direction goes in which column is arranged in the next step. In the lecture, Lin puts it as leaving the rest for to worry about.
This also says what the optimal linear autoencoder does: rotate to new coordinates, keep the first components unchanged, drop the rest, and rotate back. That is projection onto the subspace spanned by .
The optimal V: from minimizing what is dropped to maximizing what is kept
Substitute the optimal back in, and has 0 in its first diagonal components and 1 in the last . The problem on page 21 is
It minimizes the sum of squares of the components that are dropped, which is the reconstruction error. The handout replaces it with an equivalent maximization problem:
The lecture passes over the reason for the equivalence in one sentence: the length of the whole vector is fixed, so more on one side means less on the other. As a formula, , and this total does not depend on . The dropped part plus the kept part is a constant, so making the dropped part smallest makes the kept part largest. In the lecture, Lin says the switch to maximization is only because the formula is cleaner.
First, . Now only the first row of matters, and every other row is multiplied by 0. The kept quantity is , and the problem becomes
The constraint cannot be dropped. In the lecture, Lin says that if could be chosen freely, scaling it up 10 times or 100 times would raise the objective along with it, which is meaningless; is a row of an orthogonal matrix, so its length is 1 to begin with.
Arrange the data as an matrix whose row is ; then , and the objective function is . This is optimization with an equality constraint, and the handout uses a Lagrange multiplier. The lecture's explanation: at the optimal solution, the gradient of the objective function and the gradient of the constraint must be parallel. The gradient of the objective with respect to is ( is a symmetric matrix), the gradient of is , and parallel means they differ by a multiple :
A matrix times equal to times is exactly the definition of an eigenvector. So the optimal must be some eigenvector of , with the corresponding eigenvalue. Which one? Substitute this condition back into the objective function:
The value of the objective function is . To maximize it, choose the eigenvector with the largest eigenvalue, which the handout calls the 'topmost' eigenvector. This step is also the content of this section's Fun Time.
General . The handout's conclusion is that are the eigenvectors of the largest eigenvalues of . In the lecture, Lin says the proof is similar to but more complicated, does not go into it, and gives only the result. This article does not prove it either.
Back to . is 1 only in the first positions, so . Taking the columns of to be gives . The handout writes it as: the optimal are the with , that is, the top eigenvectors. The original fourth-order polynomial has an analytic solution.
The handout sums up the whole derivation in one line: the linear autoencoder projects the data onto the orthogonal patterns that 'match' most.
An addition in this article, a result that comes for free. When is an eigenvector, . So the error of the optimal solution is the sum of the dropped eigenvalues divided by :
Worked example: four points by hand
The following is an example made up for this article, not from the slides. The data is the four points of the earlier 2-1-2 autoencoder, with and :
Step 1: compute . The upper left is the sum of squares of the first coordinate, ; the lower right is the sum of squares of the second coordinate, ; the off-diagonal is the sum of products of the two coordinates, :
Step 2: find the eigenvalues and eigenvectors. Solving gives , so and . goes with ; check: . goes with ; check: .
Step 3: the optimal . With , take the largest one: .
Step 4: apply the three actions to .
- Rotate: .
- Multiply by : keep the first component and set the second to 0, giving . The encoding is the single number .
- Rotate back: .
The error is , exactly the square of the dropped component, .
Step 5: all four points.
| (kept) | (dropped) | Reconstruction | Error | |
|---|---|---|---|---|
The sum of squares of the kept column is , and that of the dropped column is ; together they make 20, equal to the total squared length of the four points, . , in agreement with the formula .
Step 6: compare with other . Use the earlier fourth-order polynomial, , where :
A wrong direction (rows two and three) or a wrong length (rows four and five) both give a larger error. has the right direction, but its length is , so the reconstructed vector is scaled up to twice the size, and its error of 5 is as bad as not reconstructing at all ().
What this result means. The optimal linear autoencoder projects every point onto the line along , keeping the coordinate sum and letting go of the coordinate difference, with an error of 0.5 per point. The earlier 2-1-2 autoencoder with uses the same direction and also has an error of 0.5. Its decoder is linear, so its reconstructed points can only fall on one straight line, and it cannot do better than the best line found here.
Projection also has a denoising effect, echoing the handout's remark in the denoising section that is a denoised version. Take the point on the line and add noise perpendicular to the line to get ; then , and the noise is removed completely. Noise along the line cannot be removed: is still after projection.
A check with numpy (np.linalg.eigh returns the eigenvalues in ascending order):
import numpy as np
X = np.array([[2, 1], [1, 2], [-2, -1], [-1, -2]], dtype=float)
eigval, eigvec = np.linalg.eigh(X.T @ X)
W = eigvec[:, [-1]] # the column for the largest eigenvalue
E_in = np.mean(np.sum((X - X @ W @ W.T) ** 2, axis=1))
print(eigval) # [ 2. 18.]
print(np.abs(W.T)) # [[0.70710678 0.70710678]]
print(X @ W @ W.T) # the four rows are (1.5, 1.5), (1.5, 1.5), (-1.5, -1.5), (-1.5, -1.5)
print(E_in) # 0.5 (up to floating-point error)
The sign of an eigenvector is not unique, and and give the same , so the code takes absolute values before printing.
PCA: subtract the mean, then do the same thing
Page 22 writes out the algorithm under the title Linear Autoencoder or PCA. On the slide, the formula in step 1 and the in step 3 are marked in red, the same color as PCA in the title, meaning these two places belong to PCA only:
- Let , and replace each with .
- Calculate the top eigenvectors of .
- Return the feature transform .
Without the red parts (no mean subtraction) it is the linear autoencoder; with them it is principal component analysis (PCA) from statistics.
One thing to watch in how step 3 is written. By the definition on page 18, is a matrix, and what encodes a -dimensional into dimensions is . What Lin says aloud in the lecture is also that the data is transformed through the transpose of before being sent out. So the of page 22 has to be read as the matrix whose rows are the ; in the notation of page 18 it is .
The handout then contrasts the objectives of the two:
- Linear autoencoder: maximize .
- PCA: maximize .
The lecture's explanation: variance is the squared gap from the mean, so shifting the data to have the zero vector as its mean and then applying the linear autoencoder naturally gives the directions with the largest variance after projection. Once the directions are found, Lin says there are two ways to use them: project the raw data onto these directions directly, or return the result of subtracting the mean and then projecting, which amounts to shifting the data first and projecting second. The red in step 3 writes the latter.
This article writes the relation between those two lines as a formula. For any unit vector , write the projected value as , whose mean is . Write as , square, and sum; the cross term is 0:
The linear autoencoder maximizes the whole left side, and PCA maximizes only the first term on the right. When the mean of the data is the zero vector the second term vanishes and the two coincide; when the mean is far from the origin the second term dominates, and the direction the linear autoencoder picks is pulled towards where the mean lies.
Worked example (made up for this article). Add to each of the four points above:
The points keep their positions relative to one another, and the mean becomes .
- Without subtracting the mean (linear autoencoder). , the eigenvalues are 34 and 18, and the largest goes with . The projected values of the four points along this direction are , whose squares sum to 34, with a variance of only 0.5. The reconstruction error is 4.5 per point.
- Subtracting the mean first (PCA). After subtraction these are the original four points, the direction is , the projected values are , and the variance is 4.5. Reconstructing with , the error is 0.5 per point.
Check the first case with the identity above: . Of the 34, 32 comes from the mean and only 2 from the variation in the data itself. Without mean subtraction, the chosen direction points at the mean of the data, and the direction along which the data actually spreads, , is not chosen.
The handout closes by saying both are useful for linear dimension reduction, which is useful for data processing, though PCA is more popular. In the lecture, Lin says PCA has a statistical background, which is why it is better known, and gives a use: when data in 10,000 dimensions is too heavy to compute with, reduce it linearly to 300 dimensions first and then do the rest.
Fun Time: what the optimal objective value is
Question (page 23): When solving the optimization problem
we know that the optimal is the 'topmost' eigenvector that corresponds to the 'topmost' eigenvalue of . Then, what is the optimal objective value of the optimization problem?
Answer: 1. The handout's solution: the objective value is simply , which is , and is 1. Written out in full: , and multiplying both sides on the left by gives . In the lecture, Lin adds that this is why we choose the with the largest .
The other choices all multiply in extra factors of . A check from this article with the four-point example: for the objective value is the sum of squares of the four projected values, , which is and not .
The summary on page 24 gives each of the four sections one line: the deep neural network is a difficult hierarchical feature extraction problem; the autoencoder is unsupervised NNet learning of representation; the denoising autoencoder uses noise as hints for regularization; PCA is a linear autoencoder variant for data processing. The preview of the next lecture is extracting 'prototype' instead of pattern. In the lecture, Lin says these two lectures were about extracting features layer by layer, and the next one takes a different approach, finding some representatives in the data.
Self-check
1. Four two-dimensional examples , , , have the zero vector as their mean. With , compute by hand the optimal , the encoding and reconstruction of , and .
Answer: , and the eigenvalues are , that is, 32 and 8. The largest goes with . The encoding of is , the reconstruction is , and the error is . .
2. A 400-50-10-1 network is to be pre-trained layer by layer with autoencoders. What is the training data of the second autoencoder? What is its structure, how many weights does it have, and how many are kept? Under the Fun Time assumption, how many seconds does pre-training take in total?
Answer: the training data is the outputs of the examples after passing through the first layer (already pre-trained and fixed), 50 dimensions each, with no labels needed. The structure is 50-10-50, with encoding weights and decoding weights, 1060 in all, of which 510 are kept as . The total time is seconds.
3. Why does the linear autoencoder assume ? If , what is the optimal , and what has been learned?
Criterion: the answer should say that when one can take to be an orthogonal matrix (for example ), so that and ; in the language of , all positions on the diagonal can hold a 1, and is all 0. This solution holds for any data and uses no structure in the data, so nothing has been learned.
4. One-dimensional data ; give each example two noisy versions , and use as a denoising autoencoder. What is the optimal ? How does it differ from the case without noise?
Answer: the four training examples are , , , . , , and . Checking with the penalty form: the mean of is 1, the noise variance is 0.25, the average error is , and differentiating gives . Without noise, ; with noise the weight shrinks, by an amount set by the variance of the noise.
5. , , and some fixed gives , , . What is the optimal ? What is then? What if is used instead?
Answer: at most two positions may be non-zero; put them where is largest and set them to 1, so . The total error is . With it is , which is worse: as soon as a kept component is scaled, extra error appears.
Exercises and corresponding reading
The corresponding weeks in two semesters.
| Edition | Week | Slides | LFD (as marked on the course page) |
|---|---|---|---|
| MOOC | Techniques Lecture 13 | 213 | not marked |
| Fall 2024 | W13 (11/25), the same week as Techniques Lecture 12 | 213u | e-7.6 |
| Fall 2026 | W15 (12/16), scheduled after the final exam in W14 | 213u still returned 404 on 2026-09-30 and was not yet public | same as above |
Textbook. e-Chapter 7 of Learning from Data (LFD) is an online chapter of the textbook and is not in the printed book; see amlbook.com for how to get it.
Homework. The homework for this week is Fall 2024 HW7 (released 2024-12-02, due 12-16). The related problems this series has written up are Q4, Q9, and bonus Q13, all three of which practice the previous lecture's content (number of weights, initial values, XOR); the explanation is in Techniques Lecture 12: Neural Networks. The guide to the whole assignment is in Techniques Homework and Final Project.
Hands-on. Take a small data set and compute the first two principal components with both numpy's np.linalg.eigh(X.T @ X) and scikit-learn's PCA, and see how much subtracting the mean or not changes the result. That is the difference made by step 1 on page 22 of the handout, and this article's example shifted by can serve as test data for checking your answer.
What came after this lecture. Layer-wise pre-training was the practice at the time of these recordings. Lin added two modern deep learning slide decks, 302u and 303u, in Fall 2024, which this series covers in Techniques Lecture 16: Finale.
Further reading. The following articles on this site overlap with this lecture and offer another way of explaining it:
- Harvard CS181 HW4: Autoencoders and VAEs: an assignment from another school with the autoencoder as its topic.
- Reading CMU 11-785 Deep Learning: a whole course devoted to deep learning.
- Reading Stanford CS230: leans toward the practice of deep learning projects.
- Reading MIT 6.7960: graduate-level deep learning.
- Reading NTU Hung-yi Lee Machine Learning 2026 Spring: the parallel track at NTU, leaning toward deep learning and generative AI.
Next lecture. Techniques Lecture 14: RBF Networks extracts features in a different way, finding representative points (prototypes) in the data and using "how close to a prototype" as the feature.
Course video sources
Original videos: Deep Neural Network, Autoencoder, Denoising Autoencoder, Principal Component Analysis
Checked: 2026-10-13. The video IDs, titles, and lengths were taken from the official playlist that day; the videos have no caption track on YouTube, and what this article reports from the lecture comes from transcripts made for it.
Update Log
- 2026-10-13: Split out from the combined article and rewritten from the handout and the video transcripts.
References
- Techniques Lecture 13 handout, 213_handout.pdf: the main source for this article. The content of the four sections, the derivation of the linear autoencoder, the four Fun Time questions, and the figures on each page all come from this handout.
- Machine Learning Techniques YouTube playlist: the IDs and titles of the four videos; what the text reports as said "in the lecture" is paraphrased from machine transcripts of these four videos.
- Hsuan-Tien Lin > MOOCs: the official entry for handouts and recordings.
- Machine Learning, Fall 2024 course page: the W13 schedule, the 213u slides, and the LFD e-7.6 marking.
- Machine Learning, Fall 2026 course page: the W14 final exam and the W15 schedule.
- Fall 2024 Homework 7 (hw7.pdf): the homework for this week.
- Learning from Data textbook website: the source of e-Chapter 7.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course and the reading routes.
Loading...