Search

Search papers and lessons

Scaling Up Visual and Vision-Language Representation Learning With Noisy Text Su

Chao Jia, Yinfei Yang, Ye Xia et al. · 2021

ALIGN trains an image encoder and a text encoder on 1.8 billion noisy alt-text pairs with one contrastive loss, and reaches state-of-the-art retrieval without expensive data cleaning.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Architectures
  • Calculus
  • Neural network basics
  • Reinforcement learning
  • ReadReady to readNot yet

TL;DR

ALIGN is a Google model from 2021 that learns images and text together from a very large, very noisy pile of web pictures and their alt-text captions. It has no hand-written labels and almost no cleaning. An image encoder and a text encoder are trained so that the right image and caption land close together, and the wrong pairings land far apart. The result is that the scale of the data makes up for its noise, and the model reaches state-of-the-art image-text retrieval and strong zero-shot classification.

Builds on: Contrastive Learning, Bi-Encoder, Zero-Shot Learning, EfficientNet, BERT · Leads to: Vision-Language Model

Why it mattered

Before ALIGN, the best vision-language pretraining sets were curated. MSCOCO needed human annotation, and Conceptual Captions needed complex filtering and post-processing, and that cost capped how big these sets could get. ALIGN showed that an image-text model could be trained on a dataset of 1.8 billion pairs, collected by a pipeline that keeps almost everything, and still beat models trained on curated data.

The same dual-encoder, same-batch contrastive loss idea became common for web-scale image-text models. It sits underneath image search, "find the photo that matches this sentence" features and zero-shot image classifiers. A reader who understands this paper can read most later vision-language papers without surprises.

The problem

Representation learning in language had moved to training on raw text with no human labels, using a masking or prediction task. Vision was still stuck on labelled datasets: ImageNet has class labels, and OpenImages has class labels too. For images paired with language, the datasets were small or expensive. Each one needed a collection process, a cleaning process, and often an expert to decide what a good caption is.

The authors' question was narrow. If you drop the cleaning and accept noise, can the sheer size of the data pay for the noise? The answer they give is yes, and the rest of the paper tests that answer.

How it works

The method has one input, a list of image-text pairs, and two outputs, an image encoder and a text encoder. Here is the path one batch takes.

flowchart LR
  A["Batch of N image-text pairs"] --> B["Image encoder (EfficientNet)"]
  A --> C["Text encoder (BERT)"]
  B --> D["Normalized image vectors x"]
  C --> E["Normalized text vectors y"]
  D --> F["N by N grid of similarity scores"]
  E --> F
  F --> G["Two softmax losses, one per direction"]
  G --> H["Update both encoders"]
  1. Collect the data. Start from English alt-text: the caption a web page author wrote for an image. Keep an image if its shorter side is more than 200 pixels and its aspect ratio is under 3. Drop images with more than 1,000 captions. Remove near-duplicates of the test images. Then apply a few frequency rules to the text: drop any alt-text shared by more than 10 images (these are often boilerplate such as file names), drop captions with rare words, and drop captions shorter than 3 words or longer than 20 words. The result is about 1.8 billion English pairs. The captions are not checked for meaning.

  2. Encode the image. A EfficientNet backbone turns the picture into a feature map, then global pooling averages each channel into one vector. The paper uses a fixed input size of 289 by 289 pixels, after resizing to 346 and taking a random crop during training. Pooling is covered in Global Average Pooling.

  3. Encode the text. A BERT-style Transformer reads the caption as a sequence of wordpiece tokens. Wordpieces are word fragments from a vocabulary; ALIGN builds one of 100,000 entries from its own data. Captions are cut to 64 tokens. The output at the special first token, called the [CLS] token, is taken as the sentence summary.

  4. Match the sizes. A linear layer, with no activation, maps the text vector to the same length as the image vector. In the main model the shared length is 1,376 for the L2 backbone; the paper shows that larger backbones want larger embeddings.

  5. Normalize both vectors. Each vector is divided by its own length, so it has Euclidean length 1. Once both are unit length, their dot product is exactly the Cosine Similarity between them, which lies between minus 1 and plus 1.

  6. Score every pair in the batch. Multiply every image vector by every text vector. With a batch of N pairs, this gives an N by N grid. The diagonal holds the true pairs. Every off-diagonal entry is a pair that does not match, and it serves as a negative example for free.

  7. Turn scores into a decision. Divide each score by a temperature σ\sigma, then apply a Softmax across each row (image to text) and each column (text to image). The entry on the diagonal should get the largest probability in its row and its column.

  8. Take the loss and update. The loss is the Cross-Entropy Loss for the diagonal entry, in both directions, added together. Gradients flow back into both encoders, and the temperature is learned along with everything else.

Check on the walkthrough. A batch of two pairs, where each image has the wrong caption, would put the true pair at the off-diagonal and give a high loss. The same batch with the right captions would give a low loss. The training signal is that difference, repeated across 16,384 pairs per batch in pretraining.

The math

Definition (ALIGN objective). For a batch of NN image-text pairs, let xix_i be the normalized image embedding of pair ii and yjy_j the normalized text embedding of pair jj. The temperature σ\sigma scales the scores. The image-to-text loss is

Li2t=−1N∑i=1Nlog⁡exp⁡(xi⊤yi/σ)∑j=1Nexp⁡(xi⊤yj/σ)L_{i2t} = -\frac{1}{N} \sum_{i=1}^{N} \log \frac{\exp(x_i^\top y_i / \sigma)}{\sum_{j=1}^{N} \exp(x_i^\top y_j / \sigma)}

and the text-to-image loss is

Lt2i=−1N∑i=1Nlog⁡exp⁡(yi⊤xi/σ)∑j=1Nexp⁡(yi⊤xj/σ)L_{t2i} = -\frac{1}{N} \sum_{i=1}^{N} \log \frac{\exp(y_i^\top x_i / \sigma)}{\sum_{j=1}^{N} \exp(y_i^\top x_j / \sigma)}

The total loss is the sum Li2t+Lt2iL_{i2t} + L_{t2i}. Here xi⊤yjx_i^\top y_j is the dot product, which for unit vectors is the cosine similarity. The paper divides by σ\sigma, so a small σ\sigma makes the softmax sharper and a large one flattens it.

Step 2 in symbols (image encoder). The image encoder ff gives f(image)∈Rdf(\text{image}) \in \mathbb{R}^{d}, and the paper normalizes it as x=f(image)/∥f(image)∥2x = f(\text{image}) / \lVert f(\text{image}) \rVert_2.

Step 3 and 4 in symbols (text encoder). The text encoder gg gives a vector of the BERT width, and a linear map WW brings it to dimension dd: y=W g(caption)/∥W g(caption)∥2y = W\,g(\text{caption}) / \lVert W\,g(\text{caption}) \rVert_2.

Step 6 and 7 in symbols. Let Sij=xi⊤yj/σS_{ij} = x_i^\top y_j / \sigma. Then Li2tL_{i2t} is the average over rows of the negative log of the diagonal entry after a row-wise softmax of SS, and Lt2iL_{t2i} is the same for columns. This is exactly the Softmax plus cross-entropy pattern, with the true class being the matching caption.

Label smoothing. The paper also uses a label smoothing value of 0.1 in both softmax losses. This is Label Smoothing: it gives a small share of the probability to the wrong entries, so the model is never pushed all the way to probability 1. The formula above omits this term for clarity.

Learned temperature. The paper initializes σ\sigma to 1.0 and trains it. It reports that the learned value settles near 1/64 in the baseline it studies, and that a hand-picked fixed value could be slightly better. The authors kept the learned value because it performs competitively and removes a sweep.

Worked numbers for the walkthrough. Take N=2N = 2 and σ=0.5\sigma = 0.5, so dividing by σ\sigma means multiplying by 2. If image 1 matches caption 1 and both unit vectors are (1,0)(1,0) and (1,0)(1,0), and image 2 matches caption 2 with (0,1)(0,1) and (0,1)(0,1), then the score grid is (2002)\begin{pmatrix} 2 & 0 \\ 0 & 2 \end{pmatrix}. The first row gives probability e2/(e2+1)≈0.881e^2/(e^2+1) \approx 0.881 to the true caption, so its loss is ln⁡(1+e−2)≈0.127\ln(1+e^{-2}) \approx 0.127. Both directions give the same, so the total is about 0.254. If the captions were swapped, the diagonal would score 0 and the off-diagonal 2, so the true probability is 1/(1+e2)≈0.1191/(1+e^2) \approx 0.119 and the loss is about 2.127 per direction.

Results

The paper evaluates on image-text retrieval, zero-shot classification, fine-tuned classification and multilingual retrieval. The headline numbers below are copied from its tables.

SettingBenchmarkALIGNComparison
Zero-shot, image to text, R@1Flickr30K 1K test88.688.0 (CLIP)
Zero-shot, text to image, R@1Flickr30K 1K test75.768.7 (CLIP)
Zero-shot, text to image, R@1MSCOCO 5K test45.637.8 (CLIP)
Zero-shot, top-1ImageNet76.476.2 (CLIP)
Frozen features, top-1ImageNet85.585.4 (CLIP ViT-L/14)
Fine-tuned, top-1ImageNet88.6490.2 (Meta Pseudo Labels)

R@1 means recall at one: the fraction of queries whose correct match is the top result (see Precision and Recall).

What the numbers mean. Zero-shot retrieval is where ALIGN is clearly ahead, mostly in the text-to-image direction. On ImageNet, the zero-shot result is close to CLIP's, and ALIGN does better on the ImageNet-R variant (92.2 against 88.9). After full fine-tuning on ImageNet, ALIGN is strong but not first; the paper says Meta Pseudo Labels is better because it uses a deeper interaction with the unlabelled data.

Limits. Every ALIGN number comes from a model trained on web data that the authors did not clean, so the claim is about scale compensating for noise, not about noise being harmless. The paper removes test images from training to keep evaluation fair. Zero-shot classification depends on the prompt template: the authors reuse CLIP's prompt ensemble, which added about 2.9 points of top-1 accuracy on ImageNet. The paper also reports that data size matters: at 3 million pairs, its noisy data trails the cleaned Conceptual Captions set, but at 6 million and 12 million it catches up quickly. A multilingual variant trained on 1.8 billion pairs across more than 100 languages is also reported, with a 250,000-entry vocabulary.

Reading guide

Read the paper in this order. Each section names the lessons it leans on.

Check yourself

QuestionIn one sentence, what does ALIGN use instead of human-curated labels, and what is the trade-off it accepts?Show answer

It uses about 1.8 billion alt-text captions from the web, with only minimal frequency-based filtering. The trade-off is noisier captions. The paper's claim is that the scale of the data makes up for that noise.

QuestionFor a batch of N pairs, how many negative pairs does a single positive pair get in the softmax, and why is that useful?Show answer

Each positive pair is compared with the other N−1N - 1 captions (or images) in the batch, so it gets N−1N - 1 negatives. The negatives come for free from the batch and grow with batch size, which makes the softmax a harder and more informative task.

QuestionTake the worked numbers in the Math section. If σ\sigma were changed from 0.5 to 1 with the same unit vectors, what would the true-pair probability in the first row become?Show answer

With σ=1\sigma = 1 the row is (1,0)(1, 0), so the probability of the true caption is e1/(e1+e0)=e/(e+1)≈0.731e^1/(e^1+e^0) = e/(e+1) \approx 0.731. The probability is lower than the 0.881 at σ=0.5\sigma = 0.5 because the larger temperature flattens the softmax.

QuestionWhy does the paper normalize the image and text embeddings before the dot product?Show answer

Normalizing makes each vector unit length, so the dot product equals the cosine similarity and depends only on the angle. The temperature then becomes the only scale on the scores, which keeps the loss stable and lets the temperature be learned.

QuestionA new team wants to build an image search for a product catalogue of 50,000 curated photos with clean titles. Would they need ALIGN's approach, and why or why not?Show answer

Probably not as a first step. ALIGN's advantage is scale: it wins by using a dataset far larger than any curated set. With 50,000 clean pairs, a smaller pretrained model fine-tuned on their own data, or a pretrained model used zero-shot, is the cheaper and more reliable choice. The dual-encoder design still applies if they want the same architecture.

Sources

Read the full paper

Chao Jia, Yinfei Yang, Ye Xia et al., 2021. arXiv:2102.05918