MIT 6.7960 — Lecture 9

Representation Learning: Introduction and Methods

§ Representations

Solving hard problems oftentimes requires finding good representations.

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 X\mathcal{X}, a representation is a function f ⁣:X→Rdf \colon \mathcal{X} \to \mathbb{R}^d that assigns a feature vector to each input x∈Xx \in \mathcal{X}.

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 XX that is labeled with outputs YY.

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 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 kk clusters based on proximity.

  1. Our representation will be a set of kk centers‾\underline{\text{centers}} {c(i)}i=1k\{c(i)\}_{i = 1}^k, so that xx is in the ithi^{\text{th}} cluster if the center closest to it is c(i)c(i).

  2. First, initialize {c(i)}i=1k\{c(i)\}_{i = 1}^k randomly.

  3. Then repeatedly replace each center c(i)c(i) with the centroid of its cluster.

The loss of a clustering is given by:

L({c(i)}):=∑x∈X∥x−c(i(x))∥2=∑x∈X∥x−D(E(x))∥2 where D is the decoder and E is the encoder.\mathcal{L}(\{c(i)\}) := \sum_{x \in X} \|x - c(i(x))\|^2 = \sum_{x \in X} \|x - D(E(x))\|^2 \text{ where } D \text{ is the decoder and } E \text{ is the encoder.}

Notice how, as indicated by the expression above, the loss of k-means clustering matches that of reconstruction-based loss.

Loss L = 1N ∑x ‖x − c(x)‖2 (mean squared distance to the assigned center) after assignment after update
4

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 kk centers, where each center is an image. Here's how the result might look for k=64k = 64, for example.

Principal Component Analysis (PCA). Recall Lecture 19 of 18.701. The point is that:

The loss of PCA is given by:

L(Wk):=∥X−XWkWk⊤∥F2=∑x∈X∥x−D(E(x))∥2, where D is the decoder and E is the encoder.\mathcal{L}(W_k) := \|X - XW_kW_k^{\top}\|_F^2 = \sum_{x \in X} \|x - D(E(x))\|^2, \text{ where } D \text{ is the decoder and } E \text{ is the encoder.}

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 L(D,E):=∑x∈X∥x−D(E(x))∥2\mathcal{L}(D, E) := \sum_{x \in X} \|x - D(E(x))\|^2.

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 L:=1∣M∣∑i∈M∥xi−x^i∥2\mathcal{L} := \frac{1}{|M|} \sum_{i \in M} \|x_i - \hat{x}_i\|^2, where MM is the set of masked patches, and x^i\hat{x}_i and xix_i 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 qikjq_ik_j like so:

We can do this with the loss L:=−log⁡exp⁡(qk+)∑jexp⁡(qkj)\mathcal{L} := -\log \frac{\exp(qk_+)}{\sum_j \exp(qk_j)}, where k+k_+ is the key matching the query qq. (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.