MIT 6.7960 — Lecture 9
Representation Learning: Introduction and Methods
§ Representations
Solving hard problems oftentimes requires finding good representations.
The game of Go was thought to be very hard because it has possible states.
Image analysis was thought to be very hard because it has possible states (say).
But we've seen in Lecture 4 that there are tricks that improve our representation of an image—specifically, our representation consists of convolutions of the image.
Definition. Given a data domain , a representation is a function that assigns a feature vector to each input .
Example. We might represent an image with one-hot vectors, where each vector states which cells contain, say, a bird.

Alternatively, one part of a representation might answer whether each cell of an image contains, say, a T-junction.

And, of course, we can chain representations together.

In fact, we can also transfer representations; not only can a model learn things about its data set, but it can also learn representations that might be useful for other data sets, too!

§ Unsupervised Learning: Auxiliary Targets
Traditional learning methods (i.e., supervised learning) require data that is labeled with outputs .
But labeling data costs time and money, and the results can be biased. What if we could still learn things without labels—some sort of unsupervised learning, perhaps?

Well, as we just saw in the previous section, representations are learnable even on unlabeled data sets, particularly if the auxiliary target used for the unlabeled data sets does not require labels.

There are two main kinds of auxiliary targets (i.e., ways to define a loss for our representation).
Reconstruction-based. How much does the data change when it is encoded and then decoded?

Here, loss is defined in the input space.
Similarity-based. Is the difference between two inputs similar to the difference between their encodings?

Interestingly, loss is defined here in the latent space.
§ Reconstruction-Based Methods
We discuss three learning methods that work well with reconstruction-based learning.
K-means Clustering. Given some data, we want to group it into clusters based on proximity.
Our representation will be a set of , so that is in the cluster if the center closest to it is .
First, initialize randomly.
Then repeatedly replace each center with the centroid of its cluster.
The loss of a clustering is given by:
Notice how, as indicated by the expression above, the loss of k-means clustering matches that of reconstruction-based loss.
You can see k-means clustering in action using the (warning: AI-generated) widget above.
A k-means clustering representation for MNIST digits is a collection of centers, where each center is an image. Here's how the result might look for , for example.

Principal Component Analysis (PCA). Recall Lecture 19 of 18.701. The point is that:
Say is a matrix consisting of the eigenvectors of with largest eigenvalue.
Our encoder then takes and expresses it in the coordinates of the principal basis: .
Our decoder just undoes this map: .
The loss of PCA is given by:
Here's the result of applying PCA on a dataset of faces.

§ Autoencoders
All of these methods discussed so far are precursors of autoencoders.
Definition. An autoencoder is any representation that learns its encoder and decoder via deep neural networks (optimized using backpropagation). Its loss, expectedly, is .

When training an autoencoder, it sometimes helps to corrupt (add noise to) the input data and train the model to recover the clean input. This produces a denoising autoencoder (DAE).

There is also autoencoding with masking (MAE). Here, we train the model to fill in intentionally-masked input.

We define the loss to be , where is the set of masked patches, and and are the model's guess and the truth, respectively.
§ Similarity-Based Methods: Contrastive Learning
There are many approaches to similarity-based learning—we focus on discussing contrastive learning here.
As a warmup, let's suppose we are in supervised learning, but now equipped with our newly learned encoder.

Now that everything is a vector, we might assign a loss by using the dot products like so:
Penalize dot products that are large when the query and key do not match.
Penalize dot products that are small when the query and key do match.
We can do this with the loss , where is the key matching the query . (This is cross-entropy loss.)
Now for the self-supervised learning case. Instead of taking dot products between image encodings and vocabulary encodings, we can take dot products between encodings of variations of the same image.

One variation on this is Momentum Contrast (MoCo), where the key encoder is a moving average of the query encoder.

A simpler variation is SimCLR (Simple Framework for Contrastive Learning), where the two encoders share weights.

There are many other similarity-based methods that we won't go over, too.
