Skip to content
— CH. 1 · CONTRASTIVE VECTOR ALIGNMENT —

Contrastive Language-Image Pre-training

~3 min read · Ch. 1 of 7
7 sections
  • In 2021, OpenAI released a model called RN50 that processed images and text into single vectors. These vectors lived in a shared space where similar pairs sat close together. The system measured similarity using the dot product between two numbers. A large dot product meant the image matched the text description well. A small dot product indicated a mismatch. This method trained models to pull matching pairs closer while pushing non-matching pairs apart. The loss function used was multi-class N-pair loss over similarity scores. Temperature parameters adjusted how strictly the model separated correct matches from incorrect ones.

  • The original CLIP implementation relied on Vision Transformers or ViT architectures for visual encoding. Model names like ViT-L/14 indicated specific patch sizes of 14 pixels. Larger variants such as ViT-B/32 used smaller patches for processing. Some versions utilized ResNet convolutional neural networks instead of transformers. The embedding dimension ranged from 512 to 1024 depending on the model size. OpenAI modified standard ResNet implementations by adding three stacked 3x3 convolutions at the start. They also introduced average pooling with stride 2 before downsampling layers. Final layers included multiheaded attention pooling mechanisms. Google researchers later developed ALIGN using EfficientNet architectures for similar tasks.

  • OpenAI trained their initial models on a private dataset named WebImageText containing 400 million image-caption pairs. These pairs were scraped directly from the internet without public release. The total word count in this collection matched the scale of the WebText dataset used for GPT-2 training. Researchers generated text queries starting with words appearing at least 100 times in English Wikipedia. Bigrams with high mutual information extended these base queries further. Names of popular Wikipedia articles and WordNet synsets added variety to the dataset. Later organizations published datasets like LAION-400M and DataComp-1B for broader community use. Google's ALIGN method extracted over one billion image-text pairs using alt-tags from online crawlers.

  • Training the largest ResNet model required 592 V100 GPUs running for 18 days straight. The biggest Vision Transformer model needed 256 V100 GPUs for 12 days of computation. Each model underwent 32 epochs of training cycles during the original OpenAI report. Later iterations like OpenCLIP utilized 384 A100 GPUs to process the LAION-2B dataset. This newer training run lasted 160 epochs and exposed models to 32 billion samples. Image resolutions varied between 224x224 pixels and larger sizes like 336x336 for specific ViT variants. FixRes techniques boosted performance by increasing resolution after initial training phases completed.

  • Users could retrieve images based on text descriptions without needing explicit annotations beforehand. Text-to-image retrieval allowed inputting descriptive phrases to find matching visuals. Image-to-text retrieval worked in reverse by finding related text content for a given picture. These capabilities enabled multimedia search functions across various platforms. Content discovery systems leveraged this alignment to connect visual and textual data efficiently. Recommendation engines used these shared embeddings to suggest relevant items to users. The technology bridged gaps between different media types through latent space alignment.

  • Classifying an image required prompting the text encoder with class names directly. The system compared the image embedding against the phrase "A photo of a {class}". The class producing the highest dot product became the output prediction. No prior training on specific categories was necessary for this task. Natural language prompts alone drove the classification process. This approach allowed immediate adaptation to new classes without retraining the model. Users simply provided the category name they wished to test against the image.

  • Models like Stable Diffusion utilized CLIP's text encoder to transform prompts into generation embeddings. Gradient signals from CLIP guided diffusion processes directly during creation. Fine-tuned versions could rank images based on aesthetic quality metrics. This ranking helped filter large datasets into smaller high-quality collections. Researchers used these tools to generate captions by matching inputs to image embeddings. Text-to-image generation tools now rely heavily on these pre-trained components. Aesthetic ranking serves as a critical step in curating visual content libraries.

Continue Browsing

Common questions

When did OpenAI release the RN50 model for contrastive language-image pre-training?

OpenAI released the RN50 model in 2021. This system processed images and text into single vectors that lived in a shared space where similar pairs sat close together.

What architectures does the original CLIP implementation use for visual encoding?

The original CLIP implementation relies on Vision Transformers or ViT architectures for visual encoding. Some versions utilize ResNet convolutional neural networks instead of transformers, with embedding dimensions ranging from 512 to 1024 depending on the model size.

How many image-caption pairs were contained in the WebImageText dataset used by OpenAI?

OpenAI trained their initial models on a private dataset named WebImageText containing 400 million image-caption pairs. These pairs were scraped directly from the internet without public release.

How long did it take to train the largest ResNet model using V100 GPUs?

Training the largest ResNet model required 592 V100 GPUs running for 18 days straight. Each model underwent 32 epochs of training cycles during the original OpenAI report.

How do users retrieve images based on text descriptions without explicit annotations?

Users can retrieve images based on text descriptions without needing explicit annotations beforehand through text-to-image retrieval capabilities. The system compares the image embedding against phrases like A photo of a class to produce predictions.

All sources

32 references cited across the entry

  1. 1conferenceLearning Transferable Visual Models From Natural Language SupervisionAlec Radford et al. — PMLR — 2021-07-01
  2. 2bookAdvances in Information RetrievalMariya Hendriksen et al. — Springer International Publishing — 2022
  3. 3webStable Diffusion Repository on GitHubCompVis - Machine Vision and Learning Research Group, LMU Munich — 17 September 2022
  4. 4citationLAION-AI/aesthetic-predictorLAION AI — 2024-09-06
  5. 5journalImproved Deep Metric Learning with Multi-class N-pair Loss ObjectiveKihyuk Sohn — Curran Associates, Inc. — 2016
  6. 6conferenceSigmoid Loss for Language Image Pre-TrainingXiaohua Zhai et al. — 2023
  7. 7conferenceA ConvNet for the 2020sZhuang Liu et al. — 2022
  8. 8citationOpenCLIPGabriel Ilharco et al. — July 2021
  9. 9arxivLearning Transferable Visual Models From Natural Language SupervisionAlec Radford et al. — 2021
  10. 10citationopenai/CLIPOpenAI — 2024-09-06
  11. 11arxivAn Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy et al. — 2021-06-03
  12. 12conferenceDeep Residual Learning for Image RecognitionKaiming He et al. — 10 Dec 2015
  13. 13arxivBag of Tricks for Image Classification with Convolutional Neural NetworksTong He et al. — 2018-12-05
  14. 14journalMaking Convolutional Networks Shift-Invariant AgainRichard Zhang — 2018-09-27
  15. 15arxivMaking Convolutional Networks Shift-Invariant AgainRichard Zhang — 2019-06-08
  16. 17arxivEfficientNet: Rethinking Model Scaling for Convolutional Neural NetworksMingxing Tan et al. — 2020-09-11
  17. 18journalLanguage Models are Unsupervised Multitask LearnersAlec Radford et al. — 2019
  18. 19bookProceedings of the 44th International ACM SIGIR Conference on Research and Development in Information RetrievalKrishna Srinivasan et al. — 2021-07-11
  19. 21journalConceptual Captions: A Cleaned, Hypernymed, Image Alt-text Dataset For Automatic Image CaptioningPiyush Sharma et al. — Association for Computational Linguistics — July 2018
  20. 22book2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)Mehdi Cherti et al. — June 2023
  21. 23journalFixing the train-test resolution discrepancyHugo Touvron et al. — Curran Associates, Inc. — 2019
  22. 25arxivExtending CLIP for Category-to-image Retrieval in E-commerceMariya Hendriksen et al. — 2021
  23. 26citationrom1504/clip-retrievalRomain Beaumont — 2024-09-07
  24. 27citationhaltakov/natural-language-image-searchVladimir Haltakov — 2024-09-03
  25. 28journalFlamingo: a Visual Language Model for Few-Shot LearningJean-Baptiste Alayrac et al. — 2022-12-06
  26. 29journalHigh-Performance Large-Scale Image Recognition Without NormalizationAndy Brock et al. — PMLR — 2021-07-01
  27. 30arxivHierarchical Text-Conditional Image Generation with CLIP LatentsAditya Ramesh et al. — 2022-04-12
  28. 31webFun With Neural Cellular AutomataJonathan Whitaker — 2022-05-22
  29. 32arxivClipCap: CLIP Prefix for Image CaptioningRon Mokady et al. — 2021