{"notes":[{"id":"contrastive-learning/simclr-v1","category":"contrastive-learning","legacyPath":"contrastive-learning/2002-simclr-v1","legacySlug":"2002-simclr-v1","legacyPaths":[],"title":"SimCLR v1","subtitle":"Winning with Batch Size","author":"Z. Yuan","paperDate":"2020-02-13","publishedOn":"2025-02-10","paperTitle":"A Simple Framework for Contrastive Learning of Visual Representations","paperUrl":"https://arxiv.org/abs/2002.05709","bibliography":{"title":"A Simple Framework for Contrastive Learning of Visual Representations","authors":["Ting Chen","Simon Kornblith","Mohammad Norouzi","Geoffrey Hinton"],"url":"https://arxiv.org/abs/2002.05709","pdfUrl":"https://arxiv.org/pdf/2002.05709","codeUrl":"https://github.com/google-research/simclr","preprint":{"id":"2002.05709","submittedOn":"2020-02-13","url":"https://arxiv.org/abs/2002.05709"},"publication":{"venue":"ICML","year":2020,"kind":"conference","url":"https://arxiv.org/abs/2002.05709"},"citation":"@misc{contrastivelearningsimclrv12020,\n  title = {{A Simple Framework for Contrastive Learning of Visual Representations}},\n  author = {Ting Chen and Simon Kornblith and Mohammad Norouzi and Geoffrey Hinton},\n  year = {2020},\n  eprint = {2002.05709},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2002.05709}\n}\n","citationPath":"/content/papers/citations/contrastive-learning/simclr-v1.d87df01ef693.bib"},"thumbnail":{"src":"/content/papers/assets/4c34c05e09e8c6506374d089b053259430ae212c9ba5b98a91e3fc0226f0d3dd.jpg","width":836,"height":612},"locale":"en","path":"/content/papers/en/contrastive-learning/simclr-v1.5be6fe43f4db.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"image-augmentations","text":"Image Augmentations","depth":3},{"id":"detailed-design","text":"Detailed Design","depth":3},{"id":"nt-xent-loss-function","text":"NT-Xent Loss Function","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"most-useful-augmentation-combinations","text":"Most Useful Augmentation Combinations","depth":3},{"id":"impact-of-augmentation-strength","text":"Impact of Augmentation Strength","depth":3},{"id":"scaling-up-the-model","text":"Scaling Up the Model","depth":3},{"id":"batch-size-impact","text":"Batch Size Impact","depth":3},{"id":"comparison-with-other-methods","text":"Comparison with Other Methods","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"contrastive-learning/simclr-v2","relation":"next","topic":"Learning from augmented image pairs"}]},{"id":"contrastive-learning/simclr-v2","category":"contrastive-learning","legacyPath":"contrastive-learning/2006-simclr-v2","legacySlug":"2006-simclr-v2","legacyPaths":[],"title":"SimCLR v2","subtitle":"Big Models Matter","author":"Z. Yuan","paperDate":"2020-06-17","publishedOn":"2025-02-11","paperTitle":"Big Self-Supervised Models are Strong Semi-Supervised Learners","paperUrl":"https://arxiv.org/abs/2006.10029","bibliography":{"title":"Big Self-Supervised Models are Strong Semi-Supervised Learners","authors":["Ting Chen","Simon Kornblith","Kevin Swersky","Mohammad Norouzi","Geoffrey Hinton"],"url":"https://arxiv.org/abs/2006.10029","pdfUrl":"https://arxiv.org/pdf/2006.10029","codeUrl":"https://github.com/google-research/simclr","preprint":{"id":"2006.10029","submittedOn":"2020-06-17","url":"https://arxiv.org/abs/2006.10029"},"publication":{"venue":"NeurIPS","year":2020,"kind":"conference","url":"https://arxiv.org/abs/2006.10029"},"citation":"@misc{contrastivelearningsimclrv22020,\n  title = {{Big Self-Supervised Models are Strong Semi-Supervised Learners}},\n  author = {Ting Chen and Simon Kornblith and Kevin Swersky and Mohammad Norouzi and Geoffrey Hinton},\n  year = {2020},\n  eprint = {2006.10029},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2006.10029}\n}\n","citationPath":"/content/papers/citations/contrastive-learning/simclr-v2.5f3668ce7e94.bib"},"thumbnail":{"src":"/content/papers/assets/aba3f0275948d5deb61c387a6c026fa81c04989b902fbaeaed8f3224206b4ae5.jpg","width":1224,"height":656},"locale":"en","path":"/content/papers/en/contrastive-learning/simclr-v2.d232ee7bc7d9.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"discussion","text":"Discussion","depth":2},{"id":"bigger-models-are-more-label-efficient","text":"Bigger Models Are More Label-Efficient","depth":3},{"id":"deeper-projection-heads-perform-better","text":"Deeper Projection Heads Perform Better","depth":3},{"id":"knowledge-distillation-effect","text":"Knowledge Distillation Effect","depth":3},{"id":"comparison-with-other-methods","text":"Comparison with Other Methods","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{"bigger-models-are-more-efficient":"bigger-models-are-more-label-efficient"},"guide":null,"relatedReading":[{"id":"contrastive-learning/simclr-v1","relation":"background","topic":"Learning from augmented image pairs"}]}],"text":"By 2020, this line of visual contrastive learning had been developing for about five years. The scene had become quite complicated and a little chaotic: not just model architectures, but training recipes too.\n\nThe authors of this paper believe that the core of contrastive learning should be simpler.\n\n## Defining the Problem\n\nRecall the essential elements of contrastive learning:\n\n- **To achieve good results, is a memory bank really necessary?**\n\nWe need a large number of negative samples to guide the model in learning better representations, and a memory bank can indeed serve this purpose. The original InstDisc did this, and later MoCo followed suit.\n\nBut it's annoying! Maintaining a memory bank during training is clearly an unfriendly design.\n\nIn this paper, the author decides to directly discard the memory bank design, opting for larger batch sizes instead. As long as we provide enough negative samples, the model can learn sufficiently good representations!\n\n\n> [!TIP]\n> \n> For readers who haven't read InstDisc or MoCo, you can refer to our previous articles:\n> \n> - [**[18.05] InstDisc: More is Better**](/blog/papers/contrastive-learning/instdisc)\n> - [**[19.11] MoCo v1: Momentum Contrastive Learning**](/blog/papers/contrastive-learning/moco-v1)\n\n\n## Solving the Problem\n\n### Model Architecture\n\n\n\n![model_arch](/content/papers/assets/4c34c05e09e8c6506374d089b053259430ae212c9ba5b98a91e3fc0226f0d3dd.jpg)\n\n\n\nThis architecture is really simple: no multiple encoders, no memory bank.\n\nThe process starts by applying two random augmentations to the same image, producing two \"seemingly different, but actually from the same source\" images.\n\nThen, both images are passed through \"the same\" encoder network to obtain two latent vectors.\n\nNext, a small projection network maps these latent vectors to the contrastive learning space, and finally, a contrastive loss function ensures that the \"same source\" augmented images are close to each other in the representation space.\n\nHuh? That's it?\n\nYes! That's it, and we've just finished reading a paper! (~Not really~)\n\n### Image Augmentations\n\n\n\n![augmentations](/content/papers/assets/39a241a3407fa349cdaaae3e148b5f7b5c67b2e7a34809eccb63a124c6e6cea5.jpg)\n\n\n\nIn SimCLR, the authors argue that strong, diverse augmentations matter even more for this contrastive task than they do for supervised classification.\n\nThe figure above shows the augmentations studied in the paper; the key ones in SimCLR's default combination include:\n\n- **Random crop**\n- **Color distortion**\n- **Gaussian blur**\n\nThe two augmented images are treated as a \"positive pair\" because they both come from the same original image.\n\n### Detailed Design\n\nFirst, for the encoder, ResNet-50 is used as the base encoder. The augmented images are input into the network to obtain a vector $h_i$. The dimensionality of this vector is typically large, such as 2048 dimensions after average pooling for ResNet-50.\n\nNext, for the projection head, the authors found that applying the contrastive loss directly on $h_i$ is less effective than adding a small MLP first. This projection network $g(·)$ typically consists of one hidden layer, followed by ReLU, and then projecting onto a 128-dimensional vector $z_i$ used for contrastive loss calculation. After training, they discard $g(·)$ and use the encoder representation $h_i$ for downstream tasks.\n\nThe most critical part is how to define the contrastive loss.\n\nThe core concept is: for the same pair $(i, j)$ (which come from the same original image), they should be as close as possible in the vector space, while being as far apart as possible from unrelated samples. Here, the authors refer to the NT-Xent (Normalized Temperature-scaled Cross Entropy Loss) formulation.\n\n### NT-Xent Loss Function\n\nNT-Xent is an InfoNCE-style contrastive cross-entropy with a specific two-view batch construction, cosine similarity, temperature scaling, and symmetric loss. L2-normalized features make their dot product equal to cosine similarity.\n\n\n> [!TIP]\n> \n> If you are interested in the paper that introduced InfoNCE, you can refer to:\n> \n> - [**[18.07] CPC: Today shapes tomorrow**](/blog/papers/contrastive-learning/cpc)\n\n\nThe NT-Xent loss function is computed as follows:\n\n$$\nℓ_{i,j}\n= - \\log \\left( \\frac{\\exp(\\text{sim}(z_i, z_j)/τ)}{\\sum_{k=1}^{2N} \\mathbf{1}[k \\neq i] \\exp(\\text{sim}(z_i, z_k)/τ)} \\right).\n$$\n\nWhere:\n\n- $z_i$ is the 128-dimensional vector obtained from the projection head after processing the $i$-th augmented image.\n- $\\text{sim}(u, v) = \\frac{u^\\top v}{\\|u\\|\\|v\\|}$ represents cosine similarity.\n- $τ$ (tau) is the temperature hyperparameter, which controls the scaling of similarity scores.\n- The numerator, $\\exp(\\text{sim}(z_i, z_j)/τ)$, represents the exponentiated similarity score between $z_i$ and the positive sample $z_j$.\n- The denominator is the sum of the exponentiated similarity scores between $z_i$ and all other vectors in the batch (excluding itself).\n\nIn a batch, assume there are $N$ original images, each undergoing two different augmentations, resulting in a total of $2N$ augmented images. For a positive pair $(i, j)$ (i.e., two different augmentations of the same original image), the loss is computed while treating the remaining $2(N - 1)$ augmented images as negative samples.\n\nThe objective is to maximize the similarity between positive samples $(z_i, z_j)$ while minimizing the similarity of all other negative samples. That is, we aim for $\\text{sim}(z_i, z_j)$ to be much greater than $\\text{sim}(z_i, z_k)$ (for all $k \\notin \\{i,j\\}$). This encourages the model to learn more discriminative representations, ensuring that similar samples cluster together while dissimilar samples are pushed apart.\n\nWithin a batch, for each positive pair $(i, j)$, both $(i, j)$ and $(j, i)$ losses are computed, then averaged over the $2N$ anchor views for backpropagation.\n\n\n> [!TIP]\n> \n> NT-Xent adapts the impact of negative samples using **cosine similarity** (with ℓ₂ normalization) and the **temperature parameter** ($\\tau$).\n> \n> - **Cosine similarity**: Ensures the model focuses on the **direction** of vectors rather than their **magnitude**, leading to a more accurate comparison of relative similarities.\n> - **Temperature parameter ($\\tau$)**:\n>   Controls the scaling of similarity scores, affecting the weighting of negative samples in the loss function:\n>   - **Small $\\tau$** → Enlarges similarity differences → Emphasizes **hard negatives**.\n>   - **Large $\\tau$** → Smooths similarity differences → Negative samples have a more balanced impact.\n> \n> In traditional contrastive loss functions, to properly handle the impact of **easy/hard negative samples**, manual **semi-hard negative mining** is often required. Without this selection, most negative samples may be too easily distinguishable (leading to excessive contrast), which could reduce the effectiveness of learning.\n> \n> However, NT-Xent dynamically adjusts the weighting of negative samples based on similarity scores using **cosine similarity + temperature scaling**, eliminating the need for manual negative sample selection. Experiments have shown that contrastive loss functions like logistic loss and margin loss generally perform worse without semi-hard negative mining. Even when semi-hard negative mining is applied, they may still not outperform NT-Xent.\n\n\n## Discussion\n\n### Most Useful Augmentation Combinations\n\n\n\n![test_on_imagenet](/content/papers/assets/c18a0ab183a1b8210e8275b29684d14e1cc1910b51c2b548f6f57482d2f9de90.jpg)\n\n\n\nTo observe the impact of different data augmentation methods (either individually or in combination) on the quality of representations learned by the model, the authors use **linear evaluation**. In this approach, the pre-trained encoder is frozen, and a linear classifier (usually a fully connected layer) is added on top, followed by top-1 accuracy evaluation on ImageNet.\n\nIn the experiment, the model input has two \"parallel augmentation pipelines.\" Here, the authors intentionally apply the tested augmentation to \"one of the pipelines,\" while the other branch applies only basic random crop + resize. This allows a clearer observation of the effects of individual augmentations or combinations, without their effects being mixed.\n\nThe interpretation of the table in the image is as follows:\n\n- **Diagonal entries**: Single transformations (e.g., Gaussian blur, color distortion), representing the application of only that augmentation to one branch.\n- **Off-diagonal entries**: Combinations of two augmentations (e.g., first Gaussian blur, then color distortion).\n- **Last column**: The average value of each row, which is the average performance under the augmentation combination for that row.\n\nThe experimental results show:\n\n- **Single augmentations** (diagonal entries) are usually not enough for the model to learn strong representations. With only one variation, the model can still rely on other invariant cues to identify \"positive pairs.\"\n- **Augmentation combinations** (off-diagonal entries) vary in their results; crop plus color distortion is notably stronger than either one alone.\n\nSuitable combinations make the contrastive task harder and improve linear evaluation in this experiment.\n\n### Impact of Augmentation Strength\n\n\n\n![augmentation_strength](/content/papers/assets/946d1a48764e7d23c9c6f69ebac9a0586f523dd69f153b53b38a751adc0917d4.jpg)\n\n\n\nWe can adjust the strength of augmentations, such as increasing or decreasing the variation in brightness, contrast, saturation, and hue. The authors further explore the impact of \"augmentation strength\" on model performance.\n\nWhen training supervised classification models on ImageNet, auto-augmentation strategies like AutoAugment are commonly used. However, the authors find that AutoAugment is not necessarily better than the \"simple crop + strong color distortion\" approach.\n\nIn the table, SimCLR rises from 59.6% at one-eighth color-distortion strength to 63.2% at full strength and 64.5% with blur. AutoAugment gives 61.1% here. The supervised row does not show the same gain from stronger color distortion, so the useful augmentation policy depends on the training objective.\n\n\n> [!TIP]\n> \n> For different learning goals, the choice of augmentation strategy may differ. However, we often subconsciously overlook this issue because other factors might seem more important.\n> \n> The author's experimental results remind us that the selection of augmentation strategies can have a significant impact on model learning effectiveness, making it worthwhile to carefully tune this aspect.\n\n\n### Scaling Up the Model\n\n\n\n![model_size](/content/papers/assets/bc771741f051c98b7718a34adb239226c356d487eb260f3acc7d0f0b582f4e11.jpg)\n\n\n\nThe figure compares model depth and width under several training durations: blue dots are SimCLR after 100 epochs, red stars are SimCLR after 1000 epochs, and green crosses are supervised ResNets after 90 epochs. In these settings, greater depth or width improves SimCLR's linear evaluation.\n\nThis resembles our experience with supervised learning: more capacity can support richer representations. Within the plotted sizes, the accuracy gap between the unsupervised and supervised models also narrows as models grow.\n\n\n> [!TIP]\n> \n> **Why does unsupervised learning perform worse with small models compared to supervised learning, but can compete when models are large?**\n> \n> The authors' experiment changes both model size and training duration. The SimCLR points at 100 and 1000 epochs and the supervised points at 90 epochs are different training conditions, so model capacity alone does not explain the narrowing gap.\n\n\n### Batch Size Impact\n\n\n\n![batch_size](/content/papers/assets/d9d26b5629c73932f953cfa6cbff80fb37b3182a7d60f5d335e4fe3a51180ed0.jpg)\n\n\n\nThe figure above shows performance at different batch sizes and training durations, with each bar representing the result from a single training experiment.\n\nTraditionally, batch size selection mainly considers computational efficiency and gradient stability. However, in contrastive learning, batch size also plays a crucial role: **it impacts the number of available negative samples**.\n\n- **Larger batch sizes mean more negative samples available per training step**, allowing the model to learn richer contrastive information and improve sample discrimination.\n- **Advantage at fewer epochs**: At 100 epochs, larger batches generally reach higher linear-evaluation accuracy in this figure. The plot compares epochs, not actual training time.\n\nThis differs from supervised learning. In supervised learning, large batches mainly aim to \"stabilize gradient estimates and improve training efficiency.\" But in contrastive learning, **more negative samples** are the core advantage brought by large batches.\n\nAnother interesting finding is that more training epochs can partially offset the disadvantages of small batches:\n\n- As training epochs increase and batches are randomly resampled, the accuracy gap between smaller and larger batches shrinks; some settings nearly meet.\n- The figure does not compare equal wall-clock time or total computation, so it cannot by itself show which batch size uses fewer resources.\n\n### Comparison with Other Methods\n\n![comparison](/content/papers/assets/3e91c5a7bbc723a3c60054e4e559aadb16a5dbb944ce0ccfb3b067a4c99dfa0c.jpg)\n\nThe authors compare the linear evaluation results of various self-supervised learning methods (i.e., freezing the backbone and adding a linear classifier on top).\n\nThe results show that a standard ResNet-50 SimCLR reaches 69.3% top-1, meeting or exceeding several earlier methods that use specialized architectures. The 4×-wide version reaches 76.5%, close to the supervised ResNet-50 reference in the figure, though their model sizes differ: about 375M versus 24M parameters.\n\nIf the number of ImageNet labels is reduced to 1% or 10%, and fine-tuning is done using class-balancing, as shown in the table below:\n\n\n\n![comparison](/content/papers/assets/357ff004443d5790c9fbcff958a19e4719ec26dcd9cc74ff946c865374e6b1ba.jpg)\n\n\n\nFor top-5 accuracy with 1% and 10% of labels, SimCLR 4× reaches 85.8% and 92.6%, the highest values in this table. Standard ResNet-50 SimCLR reaches 75.5% and 87.8%; it does not exceed every comparison method. The results show the value of these pretrained representations with few labels, while model size still matters when reading the table.\n\n## Conclusion\n\nIn this study, the authors propose a simple yet effective contrastive learning framework and thoroughly analyze the impact of various design choices on learning outcomes.\n\nThe experiments establish data augmentation, nonlinear projection heads, and NT-Xent as effective components for the reported self-supervised and semi-supervised settings. Transfer results vary by task; SimCLR does not beat every baseline on every downstream dataset.\n\n\n> [!TIP]\n> \n> Contrastive learning, with SimCLR and MoCo as the watershed, has ended the period of chaos in this field, established a clear research direction, and provided important reference points for future research.\n","imageSizes":{"/content/papers/assets/4c34c05e09e8c6506374d089b053259430ae212c9ba5b98a91e3fc0226f0d3dd.jpg":{"width":836,"height":612},"/content/papers/assets/39a241a3407fa349cdaaae3e148b5f7b5c67b2e7a34809eccb63a124c6e6cea5.jpg":{"width":1226,"height":536},"/content/papers/assets/c18a0ab183a1b8210e8275b29684d14e1cc1910b51c2b548f6f57482d2f9de90.jpg":{"width":1060,"height":636},"/content/papers/assets/946d1a48764e7d23c9c6f69ebac9a0586f523dd69f153b53b38a751adc0917d4.jpg":{"width":1040,"height":256},"/content/papers/assets/bc771741f051c98b7718a34adb239226c356d487eb260f3acc7d0f0b582f4e11.jpg":{"width":980,"height":884},"/content/papers/assets/d9d26b5629c73932f953cfa6cbff80fb37b3182a7d60f5d335e4fe3a51180ed0.jpg":{"width":1036,"height":664},"/content/papers/assets/3e91c5a7bbc723a3c60054e4e559aadb16a5dbb944ce0ccfb3b067a4c99dfa0c.jpg":{"width":4688,"height":1737},"/content/papers/assets/357ff004443d5790c9fbcff958a19e4719ec26dcd9cc74ff946c865374e6b1ba.jpg":{"width":996,"height":868}}}
