Comments
VonMateo Brems, Growth Manager at Roboflow
You must have heard of this.OpenAI CLIP model. If she looked it up, she read that CLIP stands for Contrastive Language Image Pretraining. This doesn't make a lot of sense to me right away, soI read the newspaperwhere they develop the CLIP model –and the related blog post.
I'm here to break down CLIP in what I hope will be an accessible and enjoyable read! In this post I will refer to:
- what is CLIP
- how CLIP works and
- because CLIP is cool.
What is CLIP?
CLIP is the first multimodal model (in this case vision and text) dealing with machine vision and has recently been publishedby OpenAIon January 5, 2021. As ofOpenAI CLIP-Repository, “CLIP (Contrastive Language-Image Pre-Training) is a neural network that is trained on a large number of pairs (image, text). It can be told in natural language to predict the most relevant piece of text about a given image without directly optimizing for the task, similar to the zero-trigger capabilities of GPT-2 and 3."
depends on your historyallowed forIt makes sense, but there's a lot here that you might not be familiar with. Let's unzip it.
- CLIP is a neural network model.
- It is trained on 400,000,000 pairs (image, text). An (image, text) pair can be an image and its title. This means that 400,000,000 images and their legends are compared and this is the data that is used to train the CLIP model.
- "It can predict the most relevant piece of text for an image."You can insert an image into the CLIP template and it will return the most likely title or abstract for that image.
- "not directly optimized for the task, similar to the zero-fire capabilities of the GPT-2 and 3."Most machine learning models learn a specific task. For example, an image classifier trained to classify cats and dogs would be expected to do well on the task we gave them: classifying cats and dogs. In general, we would not expect a machine learning model trained on cats and dogs to be very good at detecting raccoons. However, some models, including the CLIP, GPT-2, and GPT-3, tend to perform well on tasks for which they have not been directly trained, called "zero learning."
- "Zero learning" is when a model tries to predict a class that has seen zero times in the training data. So with a model that was trained exclusively for dogs and cats to later recognize raccoons. A model like CLIP lends itself very well to zero-shot learning because of the way it uses text information in pairs (image, text); even when the image you are actually looking at differs from the training images is different, your CLIP model will probably be able to guess the title of this image correctly.
In summary, the CLIP model is:
- a neural network model based on hundreds of millions of images and captions,
- can return the best caption for an image and
- he has impressive "zero shot" abilities, allowing him to accurately predict entire classes in a way never seen before.
when i wrote mineIntroduction to computer visionpost, I described computer vision as "the ability of a computer to see and understand what it sees in a similar way to humans."
When I taught Natural Language Processing, I described NLP similarly: "The ability of a computer to understand language in a similar way to humans."
CLIP is a bridge between machine vision and natural language processing.
It's notsoloa bridge between machine vision and natural language processing - is avery strong bridgeBetween the two, it has a lot of flexibility and many uses.
How does CLIP work?
To link images and text, both must be linkedIncorporated. He's worked with inlays before, even if he's never seen it before. Let's take an example. Suppose you have a cat and two dogs. You can represent this as a point on a graph, as shown below:

Incorporating "1 cat, 2 puppies." (Those.)
It might not sound very exciting, but we've simply incorporated this information into the X-Y grid you probably heard of in high school (formally as "euclidean space). You may also incorporate your friends' pet information into the same graph and/or you may have chosen many different ways to present that information (for example, putting dogs before cats or adding a third dimension for raccoons). .
I like to think of embedding as a way to smuggle information into math space. We just take information about cats and dogs and throw it into math space.We can do the same with text and images!
The CLIP model consists of two sub-models called encoders:
- a text encoder that embeds (squashes) text in math space.
- an image encoder that embeds (shreds) images in math space.
As long as it matches asupervised learning model, you need to find a way to measure the "goodness" or "badness" of that model - the goal is to find a model that is "better" and "least bad" possible.
The CLIP model is no different: the text encoder and the image encoder are designed to maximize the good and minimize the bad.
So how do we measure "good" and "bad"?
In the image below, you can see a set of purple text cards going into the text encoder. The output for each card would be a series of numbers. For example, the top card,Pepper the Australian dog
you would write it to the text encoder, which squashes it into math space, and it would come out as a string of numbers like (0, 0.2, 0.8).
The same is true for images: each image will be fed into the image encoder, and the output of each image will also be a string of numbers. The image of Pepper the Australian puppy will probably look like (0.05, 0.25, 0.7).

The pre-training phase. (Those.)
"goodness" of our model
In an ideal world, the sequence of numbers in the text "Pepper the Aussie Pup" will be very similar (identical) to the sequence of numbers in the corresponding image.This should be the case everywhere.: The number line in the text should be very similar to the number line in the corresponding image. One way to measure the "goodness" of our model is how close the embedded representation (string of numbers) of each text is to the embedded representation of each image.
There is a convenient way to calculate the similarity between two series of numbers:cosine similarity. We won't go into the inner workings of this formula here, but rest assured, it's a tried-and-true way to see how similar two vectors or series of numbers are. (Although it is not the only way!)
In the image above, the light blue squares represent where the text and image meet. For example, T1 is the inline representation of the first text; I1 is the embedded representation of the first image. We want the cosine similarity for I1 and T1 to be as high as possible. We want the same for I2 and T2 and so on for all the light blue squares.The greater these cosine similarities, the more "goodness" our model will have!
"Evil" of our model
Along with the desire to maximize the cosine similarity for each of these blue squares, there are many gray squares that indicate where the text and image are misaligned. For example, T1 is the text "Pepper the Aussie Pup", but perhaps I2 isa picture of a raccoon.

Image of a raccoon with bounding box annotation. (Those.)
As cute as this raccoon is, we want the cosine similarity between this image (I2) and the textPepper the Australian dog
Be very little, because this is not Pepper the Australian puppy!
While we wanted all the blue squares to have high cos similarity (since this measures "goodness"), we want all the gray squares to have low cos similarity because this measures "evil".

Maximize the cosine similarity of the blue squares; Minimize the cosine similarity of the gray squares. (Those.)
How do text and image encoders fit together?
The text encoder and image encoder are tuned simultaneously, simultaneously maximizing the cos similarity of these blue squares and minimizing the cos similarity of the gray squares in all of our text+image pairs.
Note: This can take a long time depending on the size of your data. The CLIP model was trained on 400,000,000 labeled images. The formation process took a total of 30 days.592 V100-GPU. Training on AWS On-Demand Instances would have cost $1,000,000!
Once the template is set, you can pass an image to the image encoder to get the text description that best matches the image, or alternatively you can pass a text description to the template to get an image however you want . look at some of the apps below!
CLIP is a bridge between machine vision and natural language processing.
Why is CLIP legal?
With this bridge between computer vision and natural language processing, CLIP offers many interesting benefits and applications. We will focus on applications, but we will mention some advantages:
- Generalization: Models are usually very fragile and are only capable of knowing what you have taught them. CLIP extends knowledge of classification models to a broader range of things by taking advantage of semantic information in text. Standard classification models completely discard the semantic meaning of class labels and simply number classes numerically in the background; CLIP works by understanding the meaning of classes.
- Combine text and images better than ever: CLIP can literally be the "world's best caption creator" when you consider speed and accuracy together.
- Data already tagged: CLIP is based on images and captions already created; Other state-of-the-art computer vision algorithms required significant additional human time for labeling.
Why@OpenAIIs the CLIP model the same?https://t.co/X7bnSgZ0or
— José Nelson (@josephofiowa)January 6, 2021
Some of the past uses of CLIP:
- CLIP has been used to index photos on sites like Unsplash.
- One Twitter user singled out celebrities like Elvis Presley, Beyonce, and Billie Eilish.and used CLIP and StyleGAN to create "My Little Pony"-style portraits.
- Did you play Pictionary? Now you can play online atpaint.wtf where you will be judged by CLIP.
- CLIP can be used to easily enhance NSFW filters!
- Find photos that match a mood, for example about a passage of poetry..
- OpenAI also createdDALL-E that creates images from text.
We hope you'll check out some of the above, or create your own! we have oneCLIP-Tutorialfor you to follow. if you do something with itplease let us know so we can add it to the list above!
It is important to note that CLIP isandBridge between Computer Vision and Natural Language Processing. CLIP is not the only bridge between them. You can make these text and image encoders very different, or find other ways to combine the two.However, to date, CLIP has been an exceptionally innovative technique that has stimulated further significant innovation.
We look forward to seeing what you build with CLIP and what advancements can be built with it!
Biography:Mateo Bremsis a growth manager at Roboflow.
Original. Reposted with permission.
Related:
- OpenAI launches two models of transformers that magically combine language and machine vision
- Evaluation of Object Detection Models Using Mean Average Accuracy
- Reduce the high cost of training NLP models with SRU++
- A Beginner's Guide to Q-Learning
- Cloud Computing Beginner's Guide
- A Beginner's Guide to End-to-End Machine Learning
- A Beginner's Guide to Web Scraping with Python
- Basic Machine Learning Algorithms: A Beginner's Guide
- CLIP multilingüe con Huggingface + PyTorch Lightning