- Introduced by
- LeCun, Y. (concept); Devlin et al. (BERT, NLP); Chen et al. (SimCLR, vision)
- Year
- 2018–2020 (modern consolidation)
- Type
- Learning paradigm (self-supervised pre-training + fine-tuning)
- Family
- Machine learning
What does it do?
Self-supervised transfer learning first pre-trains a model on unlabeled data, using pretext tasks whose targets are derived from the data itself, and then reuses the pre-trained encoder for a downstream task that has only a small labeled dataset.
In NLP, BERT (Devlin et al., 2019) is the reference case of masked-token pre-training followed by fine-tuning; in computer vision, SimCLR (Chen et al., 2020) applies contrastive pre-training to image representations.
The intuition behind the method
Labeled data are costly to produce, while unlabeled data are often plentiful. Self-supervised pre-training builds tasks whose targets come from the data itself, such as predicting masked words or recognizing two augmented views of the same image. Solving these tasks pushes the encoder to capture structure in the domain, so its features remain useful beyond the pretext task. Fine-tuning then needs only a small labeled set and a modest number of updates, compared with training the full network from scratch.
History
The approach has two main lines of origin. In NLP, BERT (Devlin et al., 2019) showed that masked-token pre-training followed by fine-tuning could be applied across many language understanding tasks with one architecture. In computer vision, SimCLR (Chen et al., 2020), whose title describes a simple framework for contrastive learning of visual representations, applied contrastive pre-training to image representations, using pairs of augmented views of the same image as positives.
When to use it
Choose this approach when the target task has few labeled examples but a large unlabeled corpus from a related domain exists, as with text, images, audio, or sensor streams. It fits when a pre-trained encoder matching your modality and domain is available, so that you fine-tune rather than pre-train. It is less suitable when the target domain is far from any available pre-training corpus, because transfer then depends on a domain overlap the encoder may never have been exposed to. Do not use it when a large, well-labeled target dataset already exists and a supervised model trained from scratch can be tested at low cost, or when the compute budget does not allow fine-tuning even a large encoder.
Limitations and considerations
- Pre-training large encoders is computationally expensive; in practice this cost is usually borne by whoever publishes the checkpoint, which creates dependence on those checkpoints.
- Transfer quality depends on how close the pre-training corpus is to the target data. A general-text encoder applied to specialized clinical notes may need additional domain-adaptive pre-training.
- The pretext task shapes the features toward whatever it rewards. If the target task depends on information the pretext task discards, fine-tuning may not recover it.
- Fine-tuning all layers at a high learning rate can overwrite pre-trained weights, so part of the pre-trained knowledge is lost before the target task is learned.
- In contrastive pre-training, the chosen augmentations (such as crops or color changes) encode assumptions about which invariances matter; augmentations unsuited to a domain yield features that miss the distinctions the target task needs.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Labeled examples are needed only for the fine-tuning stage, so the labeling budget can go to the target task rather than to generic feature learning.
- Because the pretext objective needs no annotation, pre-training can use corpora too large to label by hand, such as web text or unlabeled image collections.
- One pre-trained encoder can be fine-tuned for several downstream heads, so the expensive pre-training run is shared across tasks.
- Initializing from pre-trained weights, rather than random weights, typically makes fine-tuning converge faster on the target data.
Applications
- Fine-tuning pre-trained language models for text classification, named-entity recognition, and question answering, the kinds of tasks on which BERT was evaluated.
- Adapting image encoders pre-trained with contrastive objectives to classification tasks where labeled images are scarce, such as specialized medical imaging, after checking that the pre-training domain is close enough.
- Speech and audio models pre-trained on unlabeled recordings and then fine-tuned on small labeled speech corpora.
- Scientific sequence data, such as biological sequences, where labeled examples are rare but large unlabeled sequence collections exist.
- Cross-lingual transfer, where a multilingual pre-trained model is fine-tuned on a language with few labeled examples.
How it works
How it works
A pretext task is defined so that its targets are computed from the raw data, without human annotation. In the cited examples, BERT masks tokens and predicts them from their context, and SimCLR treats two augmented views of the same image as a positive pair and contrasts them against other images in the batch. The pretext task is a means to an end: the representations it produces are what gets transferred, not the pretext task's own accuracy.
During pre-training, the encoder, typically a transformer or convolutional network, is optimized on the pretext objective so that its internal representations reflect the structure of the unlabeled corpus. In contrastive methods, embeddings of views of the same item are pulled together and embeddings of different items are pushed apart. The quality of the result depends on the size and diversity of the unlabeled data and on the compute spent during pre-training.
After pre-training, the encoder is separated from the pretext-specific output layers, and its weights are used to initialize the target model. Pretext heads, such as a masked-token prediction layer or a contrastive projection head, are normally discarded. When the pre-training domain differs noticeably from the target domain, an additional stage of domain-adaptive pre-training on unlabeled target-domain data is often inserted before fine-tuning.
A task-specific head, such as a classification layer, is added to the transferred encoder. Either the whole network or only the head is then trained on the labeled target set. Using a smaller learning rate for the encoder layers than for the new head is a common way to keep pre-trained features from being overwritten early in training.
Common pitfalls
- Fine-tuning every layer at one high learning rate instead of using a lower rate for the encoder and a higher rate for the new head.
- Transferring from a pre-training corpus whose domain differs from the target without an intermediate domain-adaptive step, and then attributing poor results to the method rather than to the mismatch.
- Choosing a very large encoder for a small labeled dataset, where fine-tuning can overfit. When labeled data are small, a smaller pre-trained encoder may overfit less, so it is worth testing alongside a larger one.
- Carrying the pretext-stage projection or prediction head over into the downstream model, which does not match the architecture used for fine-tuning.
- Judging transfer only by the training loss during fine-tuning. Performance should be measured on a held-out labeled test set, ideally alongside a baseline trained from scratch on the same labels.
- Evaluating on a labeled test set that overlaps with the pre-training corpus, for example through exact or near-duplicate examples collected from the web, which inflates the apparent benefit of transfer. Check for overlap with exact and near-duplicate matching, and report results on a split that has none.
Frequently asked questions
What is the difference between self-supervised transfer learning and standard supervised transfer learning?
In standard transfer learning the source model is trained with human-provided labels on a large dataset, such as supervised ImageNet classification. In self-supervised transfer learning the source model is trained with labels derived automatically from the data itself, such as masked tokens or contrastive pairs, so the pre-training corpus does not need manual annotation.
Do I need to pre-train the model myself?
Usually not. Pre-trained checkpoints for common architectures are often publicly released, and you can typically download one and fine-tune it on your labeled data. Pre-training from scratch is mainly necessary when your domain is highly specialized and no suitable pre-trained model exists.
How much labeled data do I need for fine-tuning?
There is no fixed threshold. The amount needed depends on how close the pre-training domain is to the target and on how hard the target task is. A practical check is a learning curve on your own labeled data, comparing the pre-trained model with a model trained from scratch as the number of labeled examples grows.
When does transfer fail?
Transfer degrades when the pre-training domain is very different from the target domain (for example, a general-language model applied to highly technical clinical notes without intermediate domain-adaptive pre-training), when the target dataset is very small and fine-tuning overfits, or when fine-tuning hyperparameters, especially the learning rate, are poorly chosen.
Is self-supervised transfer learning related to few-shot learning?
Yes. Pre-trained encoders can yield features general enough that a light classifier can be fitted with few labels, which is one reason few-shot adaptation is possible. Whether this holds for a particular model should be tested on the target task.
Related methods
Sources
Chen, T., Kornblith, S., Norouzi, M., & Hinton, G. (2020). A simple framework for contrastive learning of visual representations. In Proceedings of the 37th International Conference on Machine Learning (ICML), PMLR 119, 1597–1607.
Open publication referenceDevlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of NAACL-HLT 2019, 4171–4186. Association for Computational Linguistics.
Open DOI reference