AI engineering paper · 2021
CLIP
How CLIP learned to match photos with their captions, so one model can sort images into categories it never saw labelled, and where its scores break.
You’ll learn to
- Explain how two networks, one for images and one for text, are trained to put pictures and words in one space.
- Work through the matching score used in training, and the role of its scale, with small numbers.
- Turn a list of category names into an image classifier with no labelled photos, and say where that fails.
- Describe what changed after the paper, from open reproductions to cheaper loss functions, and which weak spots remain.
Read first: Sentence-BERT
The idea in short
An image classifier is normally trained on photos labelled from a fixed list, such as the 1,000 categories of ImageNet, a well-known set of 1.28 million labelled photos. It can name only what is on the list. In 2021 a team at OpenAI built CLIP from 400 million photos that already had a caption on the internet. It was trained on one simple task: given a small group of photos and their captions, shuffled, work out which caption goes with which photo.
CLIP has two neural networks, programs with millions of adjustable numbers: one reads images and one reads text, and each turns its input into a vector, a list of numbers. Training moves a photo’s vector towards its own caption’s vector and away from the other captions in the group. Afterwards you can write each category as a sentence, such as “A photo of a dog.”, and pick the sentence whose vector is closest to the photo’s. That works with no labelled photos of the category, which is called zero-shot classification. The same vectors also let you search photos with words.
The problem
An image classifier is a program that looks at a photo and picks a category from a fixed list: dog, bicycle, traffic light. In 2020 the usual way to build one was to collect photos, pay people to give each one a label, its correct category, and train a neural network to predict the labels. The best-known collection was : 1.28 million training photos, each labelled with one of 1,000 categories. Results are usually reported as , the share of test photos where the model’s single best guess is the right label.
In 2021 Alec Radford, Jong Wook Kim and ten colleagues at OpenAI published “Learning Transferable Visual Models From Natural Language Supervision”. This guide calls it “the paper” and its model CLIP. The paper starts from the limit of that recipe. A model trained on 1,000 categories can name only those 1,000. For any other concept, such as “a cracked blender lid”, someone has to collect and label new photos first.
Language models had found another route. They learned from raw text on the web, which no one had labelled. The authors asked whether images could follow. The web is full of photos that come with text: a caption, a title, a description. That text is a free label, and unlike a fixed list it can name anything.
People had tried this before, and it had not worked well enough. The paper’s reference point is a 2017 method, Visual N-Grams, that reached 11.5% top-1 accuracy on ImageNet without using any ImageNet training photos. A 2020 system trained on ImageNet, the best the paper cites, scored 88.4%. The authors name two reasons for the gap.
- Scale. The earlier text-trained systems learned from one to two hundred thousand images. The systems that did well used millions to billions of images.
- The training task. The obvious task is to read a photo and write its caption. That is hard, because a photo can be described in countless ways. The authors found it slow to learn.
Using a model on a task it was never trained on, with no training examples for that task, is called . So the question the paper answers is: can a model trained only on photos paired with their captions learn well enough that you can name a new category in plain words and classify photos with no new labelled data, and can it be trained efficiently on hundreds of millions of pairs?