1. Home
  2. Explore
  3. Computer Science
  4. Self-Supervised Learning

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Self-Supervised Learning

Speaker 1Speaker 2

Self-Supervised Learning

27:27
0:00-27:27
  1. Anna

    Welcome to lecture seven of Deep Unsupervised Learning. So far, we’ve focused on generative models: methods such as autoregressive models, flow models, variational approaches, GANs, and energy-based models that learn to generate or model data. Today we’re shifting to a broader question: how can we learn useful features from raw, unlabeled data?

  2. Michael

    And that shift matters because generating data and learning representations are different goals. A representation is a useful way of describing an input so that another task—like classification, object detection, or segmentation—becomes easier. The name often used for learning those representations without human-provided labels is self-supervised learning.

  3. Anna

    The idea is that the data itself supplies a training signal. We create a task from the data, train a model to solve it, and then reuse the model’s learned features for downstream tasks. It’s closely related to unsupervised learning; ‘self-supervised’ emphasizes that the data creates its own supervision.

  4. Michael

    A simple example makes the value of representations clear. Imagine two clusters of points in a two-dimensional plot. In ordinary Cartesian coordinates, it may be hard to find a straight line that separates them, but if we describe the same points using polar coordinates, their different radii make the separation much simpler.

  5. Anna

    So the data hasn’t changed, but the representation has—and the task is easier. Deep learning aims to build useful representations through layers of computation. Early layers tend to capture detailed, high-frequency information, while later layers can combine those details into edges, shapes, object parts, and eventually more semantic concepts.

  6. Michael

    You can picture each layer refining what came before it. A model might begin with pixels, build up edges and contours, and then use those patterns to recognize parts of an object or an object itself. Those higher-level features can then support a downstream task.

  7. Anna

    In the hierarchy described in the lecture, deep learning is part of representation learning, which is part of machine learning, within the broader area of AI. Deep unsupervised learning focuses on learning representations with deep models but without labels. Self-supervised learning is a common name for this approach.

  8. Michael

    Why put so much effort into learning without labels? Because labels can be expensive to create. Building a labeled dataset can involve defining categories, writing annotation instructions, recruiting people, designing interfaces, and building storage and data-processing systems.

  9. Anna

    And the cost varies by domain. Images of familiar objects may already have widely available labels, but creating a high-quality dataset in medicine or law can be much more difficult. Meanwhile, the internet contains enormous amounts of unlabeled images, text, audio, and video that supervised learning alone can’t directly exploit.

  10. Michael

    The aim isn’t necessarily to choose between supervised and unsupervised learning. Instead, we can use unlabeled data to learn a strong starting representation, then use a smaller labeled dataset for the task we care about. That could make downstream learning faster, cheaper, and more data-efficient.

  11. Anna

    There’s also a cognitive motivation: people and animals learn a great deal through observation and experience, not only by being given explicit labels. The lecture quotes Pierre Sermanet: ‘Give a robot a label and you feed it for a second; teach a robot to label and you feed it for a lifetime.’ The point is that learning richer concepts may help a system generalize beyond a list of labeled examples.

  12. Michael

    So what does a self-supervised task look like? Often, we hide or alter part of an example and ask a neural network to predict what’s missing, using the rest. We might mask words in a sentence, hide frames in a video, predict a future frame from earlier ones, or reconstruct part of an image.

  13. Anna

    The task we invent is called a pretext task or proxy task. Its quality matters: a model can solve an easy task without learning the features we want, while a well-designed task can encourage it to capture useful structure. The representation is not automatically good just because the model successfully predicts something.

  14. Michael

    That’s why pretraining is so appealing. A classifier trained on a large labeled dataset, such as ImageNet, can serve as a feature backbone for other vision tasks. The lecture gives examples including object detection with Faster R-CNN or RetinaNet, instance segmentation with Mask R-CNN, and semantic segmentation with a fully convolutional network.

  15. Anna

    In each case, the pretrained features provide a useful starting point. That can reduce the amount of labeled data needed for the harder task and help training converge faster. The goal of self-supervised learning is to get similarly useful—or potentially better—features without relying on a large labeled dataset.

  16. Michael

    The lecture also uses Yann LeCun’s ‘cake’ analogy: self-supervised learning is the cake, supervised learning is the icing, and reinforcement learning is the cherry. The image is meant to emphasize how much learning might come from predicting structure in raw data.

  17. Anna

    But we shouldn’t take the analogy too literally. A label such as ‘cat,’ or a human-provided bounding box around an object, can be a more meaningful signal than saying that two pixels match or that an image has been rotated. It’s not only the number of bits in a learning signal that matters; the quality and real-world relevance of those bits matter too.

  18. Michael

    A general recipe is to create a prediction problem from the data: hide a region, choose different views of an example, or alter an input, and ask the model to predict the missing or related information. The crucial question is whether the model can solve the task only by learning something useful, rather than by exploiting a shortcut.

  19. Anna

    For example, filling a few missing video frames might be easy if the model can interpolate pixels using nearby frames. That doesn’t necessarily mean it understands the objects in the scene. Predicting missing words in a sentence may demand more about grammar and meaning, because simply copying nearby words usually won’t reconstruct the sentence.

  20. Michael

    The lecture organizes its methods around three broad ideas. First, corrupt the data and predict the original. Second, invent visual common-sense tasks, such as predicting patch positions, solving jigsaw puzzles, or recognizing image rotation. Third, learn by contrasting a true related example with alternatives.

  21. Anna

    Let’s start with denoising autoencoders. We add noise to an input, pass the noisy version through an encoder, and train a decoder to reconstruct the original. The encoder’s compressed representation is the feature we hope will capture the underlying signal rather than the corruption.

  22. Michael

    If we add no noise, an autoencoder might simply learn the identity function: copy the input to the output. Adding noise makes reconstruction more demanding and can encourage the model to learn patterns that let it recover what was obscured. But too much noise can make the original signal very difficult to recover.

  23. Anna

    The lecture describes three kinds of pixel-level corruption from the original denoising-autoencoder work. Additive isotropic Gaussian noise perturbs pixel values. Masking noise sets a randomly chosen fraction of pixels to zero. Salt-and-pepper noise randomly pushes selected pixels to a minimum or maximum value.

  24. Michael

    One way to think about this is geometrically. Each input is surrounded by possible distortions created by the noise, and the model learns to map those distorted examples back toward the data. In that sense, it is learning local structure around the data manifold.

  25. Anna

    The reconstruction loss can be applied to the output pixels, and the noisy pixels can be given extra importance so the model has to work to restore them instead of merely copying the untouched parts. The lecture mentions both mean squared error and binary cross-entropy as possible losses; for MNIST, cross-entropy can be a natural choice, though either can work with suitable settings.

  26. Michael

    A stacked denoising autoencoder repeats the process layer by layer. First, we learn features from the image; then we can corrupt those features and learn to reconstruct them at the next level. The hope is that higher layers represent increasingly abstract information, although the choice of noise and activation matters.

  27. Anna

    Once the features have been learned, we can freeze them and train a supervised classifier on top. This was especially useful historically, when directly training deep neural networks for supervised learning was difficult. The lecture notes that denoising autoencoders learned visible digit-stroke features, and their features supported MNIST classification.

  28. Michael

    A related method is the context encoder. Instead of adding noise to individual pixels, it masks a region of an image and asks a model to fill it in. Because the complete image is already available during training, the original contents of the masked region provide the target without requiring a human label.

  29. Anna

    You could mask the center of an image, or hide several smaller regions. The lecture also describes masking an object using a segmentation mask, but that version requires a segmentation mask and therefore isn’t fully self-supervised in the same way as masking regions without labels.

  30. Michael

    The reconstruction loss can be measured only on the masked pixels. A straightforward pixelwise loss, such as mean squared error, often produces blurry completions because averaging several plausible answers can be safer than choosing one sharp answer.

  31. Anna

    To encourage sharper predictions, the context-encoder work combined reconstruction with an adversarial loss. A discriminator tries to distinguish real image content from the model’s predicted content, while the reconstruction term encourages the completion to match the particular image. Combining them can produce sharper results than a pixelwise loss alone, though adversarial predictions can introduce details that don’t fit the surrounding scene.

  32. Michael

    That trade-off is important: a plausible-looking patch isn’t always a faithful completion of the original image. In the reported transfer experiments, context-encoder features did better than ordinary autoencoder features on some Pascal tasks, but they still fell short of features pretrained with ImageNet labels. So the method was promising without closing the gap.

  33. Anna

    The next principle is predicting one view of data from another. A particularly clear example is colorization: take a grayscale image and predict its color channels. Converting a color image to grayscale is easy, but recovering its color requires adding information that isn’t present in the grayscale input.

  34. Michael

    To do that, the model may need to recognize objects and their typical appearance—such as green leaves or brown bark—and understand edges and regions in the image. The lecture describes representing an image with an L channel for lightness and a and b channels for color, then using the L channel to predict the a and b channels.

  35. Anna

    If we train that prediction with ordinary mean squared error, the model can average several possible colors and produce dull or unrealistic results. One solution is to quantize the color values into discrete categories and treat prediction as classification, using a softmax and cross-entropy-style loss. The lecture connects this approach to the benefits of discrete prediction in autoregressive image models.

  36. Michael

    Another version is a split-view, or split-brain, autoencoder. Separate the input into two views, train each side to predict the other, then combine the predictions and encourage them to be consistent with the original input. The same general idea could apply to predicting depth from color or color from depth.

  37. Anna

    Now for visual common-sense tasks. Relative patch prediction asks a model to look at two image patches and identify their relative positions. For instance, given a reference patch and another patch, it might have to classify whether the second patch is above, below, left, right, or in one of the diagonal positions.

  38. Michael

    The labels come for free: sample patches from the same image, and their positions tell you the answer. To solve the task, the model may learn both visual features and spatial relationships—for example, how an ear is positioned relative to a face.

  39. Anna

    But shortcuts can ruin the task. If patches overlap, the model might identify their relative positions from shared boundary pixels rather than understanding the image. The work therefore used non-overlapping patches and applied spatial and color jittering to make superficial cues less reliable.

  40. Michael

    A closely related idea is to make the model solve a jigsaw puzzle. Divide an image into a three-by-three grid, shuffle the patches, and ask the model to identify their original arrangement. There are nine factorial possible arrangements, so one practical formulation is to select permutations and treat the correct arrangement as a classification category.

  41. Anna

    The model can encode each patch with a shared convolutional network, combine the patch representations, and predict the arrangement. Like relative-position prediction, the task encourages spatial reasoning and visual associations, though it still matters whether the model can exploit shortcuts.

  42. Michael

    A simpler pretext task is rotation prediction. Rotate an image by zero, ninety, one hundred eighty, or two hundred seventy degrees, then train the model to predict which rotation was applied. The lecture’s intuition is that recognizing a rotation may require understanding the orientation of objects and scenes—for example, noticing that a face is upside down.

  43. Anna

    That makes the task geometrically grounded in how images are captured. The lecture reports that using four right-angle rotations worked better than using only two orientations, while adding still more finely spaced rotation angles did not improve the reported result. More elaborate labels do not automatically make a better pretext task.

  44. Michael

    In the comparisons discussed, rotation prediction improved on earlier self-supervised methods for ImageNet features and transferred well to Pascal classification, detection, and segmentation. But supervised ImageNet features still had a substantial advantage on some downstream measures. So the puzzle-based tasks showed real progress, not a complete solution.

  45. Anna

    Our third principle is contrastive learning, and a foundational example comes from language: Word2vec. The goal is to represent words as vectors so that words used in related contexts have useful geometric relationships. Earlier approaches built word co-occurrence matrices and applied techniques such as singular value decomposition.

  46. Michael

    Those matrix-based approaches can run into sparsity, computational cost, and difficulties with infrequent words. Very common words can also dominate unless the method uses additional heuristics. Word2vec instead learns embeddings through prediction tasks based on neighboring words.

  47. Anna

    There are two main Word2vec formulations. CBOW—continuous bag of words—uses surrounding words to predict a center word. Skip-gram does the reverse: it uses a center word to predict the surrounding words.

  48. Michael

    In CBOW, the model can average the embeddings of the surrounding words and use that representation to score possible center words. In skip-gram, it predicts surrounding words from the center representation, often treating those surrounding-word predictions as conditionally independent given the center word.

  49. Anna

    A full softmax over every word in a large vocabulary can be costly. Word2vec used efficiency techniques such as negative sampling and hierarchical softmax rather than repeatedly normalizing over the entire vocabulary in the most direct way.

  50. Michael

    The learned vectors can capture relationships in a strikingly consistent way. For example, the vector difference between a country and its capital can be similar across country-capital pairs. Word embeddings can also bring related entities together, such as a company and its leader, or a country and an airline associated with it.

  51. Anna

    That’s the bridge to contrastive predictive coding, or CPC. You can think of CPC as extending the Word2vec idea beyond text: use a context to identify a related target among a set of possible alternatives, while representing many kinds of data with neural networks.

  52. Michael

    For audio, the context might be a portion of a waveform, and the target might be a later audio chunk. An encoder represents the chunks, and a context network—such as a recurrent model—summarizes what came before. Instead of reconstructing the exact future waveform, CPC tries to make the context representation match the true future representation better than it matches negative examples.

  53. Anna

    This is a contrastive classification problem: given the context and a true future target among several candidates, identify the real one. A similarity score, such as a dot product or a learned bilinear score, compares the context and target representations. The resulting objective is often referred to as InfoNCE.

  54. Michael

    The negative examples are not a minor implementation detail. Negatives from other speakers can encourage features that distinguish speakers; negatives from the same speaker can encourage more fine-grained phonetic information. What you contrast against helps determine what the model learns.

  55. Anna

    CPC also generalizes the choice of context and target. You might predict the future from the past, reverse that direction, or use information around a masked section to predict what belongs in the middle. But the prediction must be nontrivial: if the context overlaps the target too much, the model may succeed by copying shared information.

  56. Michael

    The choice of prediction distance matters too. Audio waveforms change rapidly, while useful speech information—such as phonemes—can vary more slowly. Predicting a suitable distance into the future may encourage the model to capture those more meaningful features rather than just nearby signal details.

  57. Anna

    In the lecture’s audio results, CPC representations worked well for speaker and phoneme classification when the features were frozen and a simple classifier was trained on top. They substantially outperformed the engineered MFCC features described in the comparison, and an MLP could bring phoneme classification closer to supervised performance.

  58. Michael

    The results also show why negative sampling and prediction distance need care. Negatives from the same speaker changed the balance of what was learned, and predicting farther into the future was not always better. If the target becomes too hard to infer from the context, the model may receive little useful shared information.

  59. Anna

    CPC was also applied to images. The model divides an image into overlapping patches, encodes them, and arranges the embeddings in a grid. A context network then uses some of the grid to predict representations in other locations, rather than predicting raw pixels.

  60. Michael

    The image version used a masked convolutional network to summarize context without letting information from the target region leak into the prediction. In the reported comparison, CPC achieved a higher linear-classification result than several earlier self-supervised methods, including colorization and patch-based tasks.

  61. Anna

    Still, the first version of CPC remained well below supervised ImageNet classification in that comparison. That gap motivated CPC version two, which retained the predictive, contrastive framework but improved the architecture, scale, and training details.

  62. Michael

    CPCv2 used a deeper and wider image encoder, a wider PixelCNN context model, larger image patches, and extensive spatial and color augmentation. It also focused its prediction on a carefully chosen offset instead of predicting many targets indiscriminately, and used a large set of negatives drawn from patches in the batch.

  63. Anna

    The evaluation asked several different questions. Could a linear classifier use the frozen features? Could a model fine-tune them with only a fraction of the labels? And could the pretrained representation transfer to another dataset and task, such as Pascal detection?

  64. Michael

    In the lecture’s reported results, CPCv2 substantially improved the linear-classification score over CPC’s first version. More importantly, pretraining on unlabeled data made image recognition much more data-efficient: in the low-label setting, it could outperform training from scratch with the same small number of labels.

  65. Anna

    The gains were not limited to having very few labels. The reported fine-tuning results also improved on supervised training across the label regimes shown, including when all labels were available. And the Pascal transfer results helped demonstrate that the learned features could benefit object detection, not only image classification.

  66. Michael

    The lecture’s broader message from CPCv2 is that careful engineering matters: the encoder, patch size, prediction direction, augmentations, negative examples, and training duration can all make a difference. A simple underlying objective can become much stronger when those choices are made well.

  67. Anna

    That leads to a simpler form of contrastive learning called instance discrimination. Instead of predicting a spatial patch or future audio chunk, take two different augmented views of the same image as a positive pair. Treat other images as negatives, and train the model to recognize that the two views came from the same instance.

  68. Michael

    For example, one view might be a random crop with grayscale applied, and the other might use a different crop and a flip. If the transformations make the views different enough, the model has to learn features that stay useful across those changes, rather than simply matching identical pixels.

  69. Anna

    Two influential approaches in the lecture are Momentum Contrast, or MoCo, and SimCLR. Both use the same broad positive-versus-negative idea, but they differ in how they obtain and maintain the negative examples.

  70. Michael

    MoCo describes contrastive learning as a dictionary lookup. The model encodes a query and a set of keys, then tries to pick the key that corresponds to another augmentation of the same image. A contrastive loss scores the positive key against many negative keys.

  71. Anna

    The challenge is that a minibatch limits how many negatives you can use. MoCo addresses that with a queue, or memory bank, of previously encoded keys. To keep those stored representations reasonably consistent with the current model, it uses a key encoder updated as a momentum, or slowly changing, version of the query encoder.

  72. Michael

    The query encoder receives the gradient updates, while the key encoder is updated through the momentum rule rather than backpropagation. New keys enter the queue and old ones leave. That gives MoCo many negatives without requiring all of them to come from an extremely large current minibatch.

  73. Anna

    The lecture contrasts that with end-to-end contrastive learning, where the queries, keys, and negatives all come from the current minibatch and the shared encoder is trained directly. That approach is simpler, but it benefits from large batches. MoCo’s queue makes it possible to use a large dictionary with a more modest batch.

  74. Michael

    SimCLR takes the end-to-end route and makes large batches central to its approach. It creates two augmented views for each image, sends them through the same ResNet, and contrasts the resulting representations against the other examples in the batch.

  75. Anna

    A key SimCLR addition is a small projection head, an MLP that maps the ResNet representation into a different space for the contrastive objective. The lecture reports that this head helped performance. SimCLR also used strong augmentations, including Gaussian blur, and trained with large batches for a long time.

  76. Michael

    The lecture reports that SimCLR produced a major improvement in linear evaluation over earlier results, especially when the encoder was made wider. It showed that contrastive self-supervision could approach supervised performance in some settings, though comparisons depend on model size, training scale, and evaluation.

  77. Anna

    MoCo’s follow-up, MoCov2, adopted several successful SimCLR details: an MLP projection head, stronger augmentations such as Gaussian blur, a cosine learning-rate schedule, and longer training. The lecture reports that these changes substantially improved MoCo, while keeping its momentum encoder and queue.

  78. Michael

    That comparison reinforces a practical lesson: strong self-supervised results depend on more than the broad idea of contrasting positives and negatives. Model capacity, data augmentation, batch size or queue design, optimization, and training duration all matter.

  79. Anna

    So let’s pull the methods together. Denoising and context encoders corrupt or mask inputs and reconstruct what was there. Colorization predicts one view from another. Relative-position, jigsaw, and rotation tasks create visual prediction problems. Word2vec and CPC teach representations by identifying related context and target examples, and instance discrimination contrasts two views of the same image against others.

  80. Michael

    Across all of them, the central question is the same: does the pretext task force the model to learn features that transfer? A shortcut can make a task easy but unhelpful. A well-chosen task, together with suitable data and training choices, can produce representations that reduce the need for task-specific labels.

  81. Anna

    This lecture focuses mainly on computer vision and foundational ideas. It does not cover later language-pretraining methods such as BERT in detail, nor the use of unsupervised learning for reinforcement learning; those topics are assigned to separate lectures. Semi-supervised learning—using unlabeled data alongside labeled data—also comes later.

  82. Michael

    And there’s an important caveat: the historical results and comparisons discussed here belong to the methods and experiments in the lecture. The field was progressing rapidly, and a reported state of the art was not a timeless claim. What remains useful is the framework: create supervision from data, learn a representation, and test whether it helps real downstream tasks.

  83. Anna

    That’s the promise of self-supervised learning: not replacing every human label, but making far better use of the data we already have. Learn from unlabeled examples first, then use labels where they provide the most value. That’s how pretraining can make downstream learning more efficient and potentially more general.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent