ビジュアルAIガイド

CLIP および視覚言語モデル

CLIP (Contrastive Language-Image Pre-training) is a 2021 OpenAI model that trains an image encoder and a text encoder to place matching pictures and captions close together in one shared vector space.

このガイドを聴くAIによるナレーション · ~9 min

このページでは10分で読めます
  1. 概要
  2. 主なポイント
  3. ディープダイブ
  4. Zero-shot classification of one photo with CLIP
  5. 現実世界の実装
  6. CLIP と視覚言語モデルの将来
  7. 実践する
  8. 出典とさらなる参考文献
  9. 探検を続けましょう
  10. よくある質問

概要

That shared space lets software classify, search and filter images with plain-language descriptions, and CLIP-style encoders became the visual front end of many text-to-image and multimodal chat systems.

主なポイント

  1. CLIP trains an image encoder and a text encoder together so matching images and captions end up close in one shared embedding space.
  2. OpenAI trained CLIP on 400 million web image-text pairs with a batch size of 32,768.
  3. The best CLIP model reached 76.2% zero-shot ImageNet accuracy, matching a supervised ResNet-50 without using ImageNet's labeled training images.
  4. CLIP scores how well text matches an image; it does not generate images or captions by itself.
  5. Stable Diffusion v1 uses a CLIP text encoder, and LLaVA uses a CLIP image encoder feeding a language model.
  6. The CLIP paper documents weak spots in counting, fine-grained categories and handwritten digits, scoring 88% on MNIST.

ディープダイブ

CLIP, short for Contrastive Language-Image Pre-training, is a pair of neural networks described by OpenAI researchers in the paper "Learning Transferable Visual Models From Natural Language Supervision", posted to arXiv on 26 February 2021. One network, the image encoder, turns a picture into a fixed-length list of numbers called an embedding. The other, the text encoder, turns a sentence into an embedding of the same length. Training pulls the embedding of an image toward the embedding of its real caption and pushes mismatched pairs apart. CLIP does not draw images or write captions. It scores how well a piece of text describes an image, and that single ability supports classification, search, content filtering and the conditioning of image generators. A vision-language model (VLM) is the broader family of systems that process images and text together, and CLIP is the encoder much of that family was built on.

The training data came from the web. The authors assembled 400 million image-text pairs from publicly available internet sources, keeping pairs whose text contained one of 500,000 search queries and capping each query at about 20,000 pairs. In every training step a batch of N pairs (32,768 in the paper) passes through both encoders. Each output is projected by a single linear layer into the shared space and normalized to unit length. The model then computes the cosine similarity of every image with every text, an N by N grid. The N true pairs sit on the diagonal and every other cell is a negative example. A cross-entropy loss asks each row to pick its correct caption and each column to pick its correct image, and the two losses are averaged. A learned temperature scales the similarities before the softmax; the paper initializes it to the equivalent of 0.07 and clips it so logits are never multiplied by more than 100.

Zero-shot classification reuses that scoring ability without any task-specific training, which is what zero-shot means. To sort an image into 1,000 categories, write one short sentence per category, such as "a photo of a dog", embed all of them with the text encoder, embed the image, and choose the sentence with the highest similarity. The paper points out that the text embeddings behave like the weights of a linear classifier, so they are computed once and cached. Wording matters. Prompt engineering combined with an ensemble of 80 context templates improved ImageNet accuracy by almost 5 percentage points over bare class names, with the ensemble alone adding 3.5 points.

The headline results set the template for later work. OpenAI trained five ResNet and three Vision Transformer (ViT) image encoders for 32 epochs each. The largest ResNet, RN50x64, took 18 days on 592 V100 GPUs; the largest ViT took 12 days on 256 V100 GPUs. The best model, ViT-L/14 given one extra epoch at 336-pixel resolution, reached 76.2% zero-shot top-1 accuracy on ImageNet, matching the original supervised ResNet-50, and 95% top-5. On seven natural distribution-shift test sets, including ImageNet Sketch and ObjectNet, zero-shot CLIP models shrank the gap between ImageNet accuracy and shifted accuracy by up to 75%. The paper also showed smooth scaling: average zero-shot error across 39 evaluations followed a log-log linear trend over a 44x range of compute.

Milestones followed quickly. Stable Diffusion v1 used a frozen CLIP ViT-L/14 as its text encoder. The OpenCLIP project reproduced the recipe on open data such as LAION-2B and DataComp-1B. Google's SigLIP paper (March 2023) swapped the softmax loss for a pairwise sigmoid loss and, combined with locked-image tuning, reported 84.5% zero-shot ImageNet accuracy after two days on four TPUv4 chips. LLaVA (April 2023) turned CLIP into the eyes of a chat assistant: features from a pretrained CLIP ViT-L/14 pass through a projection matrix into the Vicuna language model, which was then tuned on 158,000 machine-generated instruction-following samples. Its authors report an 85.1% relative score against GPT-4 on a synthetic benchmark and 92.53% on ScienceQA when combined with GPT-4. In this design CLIP no longer makes the final decision; it supplies visual features that a large language model reads alongside text.

Compared with a supervised classifier trained on a fixed label list, CLIP trades some peak accuracy on any one benchmark for flexibility, because any category that can be described in words is a valid label. The paper measured why the contrastive design was chosen: matching whole captions learned zero-shot ImageNet transfer 4x more efficiently than predicting a bag-of-words version of the caption, which was itself 3x more efficient than a transformer predicting the exact caption. ViTs were about 3x more compute-efficient than ResNets as CLIP image encoders. Fine-tuning a CLIP model on ImageNet raised ImageNet accuracy by 9.2% but erased most of its robustness advantage on shifted data. Against SigLIP, standard CLIP needs a softmax normalized over the whole batch, while the sigmoid loss treats each image-text pair as an independent yes-or-no decision and, per its authors, outperforms softmax by a large margin below batch sizes of 16,000.

The limitations are documented in the paper itself. Zero-shot CLIP is weak at fine-grained distinctions such as car models, flower species and aircraft variants, at counting objects, and at unfamiliar tasks such as estimating the distance to the nearest car, where it can be near chance. It scored 88% on MNIST handwritten digits, below logistic regression on raw pixels, because almost no digit-like images appear in its training data, and 51% on full street-number recognition (SVHN). Because CLIP learned to read text in images, OpenAI researchers described typographic attacks in the March 2021 Distill article "Multimodal Neurons in Artificial Neural Networks", where written words in a photo can steer the classification. Web-scraped captions also carry the associations and gaps of their sources, so outputs should be audited before use in sensitive settings.

In practice, running CLIP is cheap and training it is not. Classification costs one image-encoder pass per image plus one text-encoder pass per label, and label embeddings are reused across all images. Search systems store image embeddings in a vector index and compare each query by cosine similarity. Training from scratch is the expensive part: the original runs used hundreds of V100 GPUs for up to 18 days, and a batch of 32,768 forced the similarity computation to be sharded across GPUs. SigLIP found that a batch of about 32,000 is sufficient and that gains fade as batches grow toward one million, which lowers the bar for smaller labs. Most practitioners start from released weights, such as OpenAI's checkpoints or OpenCLIP models, and add a small trained linear layer when zero-shot accuracy is not enough.

04作業例

Zero-shot classification of one photo with CLIP

  1. Load a released CLIP checkpoint, for example an OpenAI ViT-B/32 or an OpenCLIP model, together with its image preprocessing and tokenizer.

  2. Write one prompt per candidate label, such as 'a photo of a cat', 'a photo of a dog' and 'a photo of a car'.

  3. Run the prompts through the text encoder and L2-normalize the three resulting embeddings; cache them for reuse.

  4. Resize and crop the photo with the model's preprocessing, run it through the image encoder, and L2-normalize the embedding.

  5. Compute the dot product between the image embedding and each text embedding, multiply by the model's learned scale, and apply a softmax.

  6. Read off the label with the highest probability, then add more template wordings and average their embeddings to see whether the prediction stabilizes.

それが示すもの

A probability for each label, computed without any task-specific training. To check it, run a small labeled set of your own images through the same steps and compare accuracy with and without prompt ensembling; the CLIP paper reports that ensembling helps on ImageNet.

現実世界の実装

Stable Diffusion v1-4 conditions its image generator on a frozen, pretrained CLIP ViT-L/14 text encoder, so the prompt a user types becomes CLIP text embeddings before any denoising starts.

LLaVA (2023) connects a pretrained CLIP ViT-L/14 image encoder to the Vicuna language model through a simple projection matrix, letting a chat model answer questions about photos.

Zero-shot image classification: the original CLIP paper reports 76.2% top-1 ImageNet accuracy from class names alone, without training on any of ImageNet's 1.28 million labeled images.

Text-to-image search over a photo collection: every image is embedded once, a query such as 'a red bicycle in snow' is embedded at search time, and results are ranked by cosine similarity.

Open reproductions such as OpenCLIP train CLIP-style models on public datasets; its ViT-bigG-14 trained on LAION-2B reports 80.1% zero-shot ImageNet accuracy in the project README.

CLIP と視覚言語モデルの将来

Several research directions grew directly out of CLIP's documented weaknesses. Data quality is one: the OpenCLIP project reports that the same architecture trained on different public datasets, for example LAION-2B versus DataComp-1B, reaches noticeably different zero-shot accuracy, so dataset curation has become a research topic of its own. Loss design is another: the 2023 SigLIP paper showed that a sigmoid loss decouples batch size from normalization and found little benefit beyond batches of about 32,000, shifting attention from raw scale to efficiency. The largest shift is in how the encoders are used. Since LLaVA's April 2023 release, a common recipe is to keep a contrastively trained image encoder and project its features into a large language model, so open questions now include how to preserve fine detail, text in images and spatial relations that a single global embedding discards. The weaknesses listed in the 2021 paper, such as counting, fine-grained categories and typographic attacks, remain useful test cases for any new vision-language model, and published evaluations rather than marketing claims are the reliable way to judge whether a newer system has closed them.

実践する

なぜそれが重要なのか

  • 速度とスケール. Visual AI は、検査、検出、タグ付けタスクを大規模に自動化できます。
  • ビルドの選択. クリエイティブ チームは、手動での修正を減らし、より迅速にコンセプトのプロトタイプを作成できます。
  • チームとワークフロー. 以前は処理が困難であった画像信号やビデオ信号を操作に使用できるようになります。

気をつけてください

  • 出所が不明瞭な場合、肖像権と同意が法的リスクとなる可能性があります。
  • モデルのパフォーマンスは、照明、人口統計、環境によって異なる場合があります。
  • 信頼度のしきい値が監視されない限り、誤検知は気付かれない可能性があります。

次のステップ

  1. 精度、再現率、エラーコストの許容基準を定義します。
  2. 実際の生産条件に一致するデータを使用してテストします。
  3. 信頼性の低い予測や影響の大きい予測については、人間によるレビューを追加します。
  4. モデルのドリフトを追跡し、カメラまたはデータセットの変更後に再検証します。

出典とさらなる参考文献

  1. arXiv (OpenAI)自然言語の監督からの移転可能な視覚モデルの学習
  2. arXiv (Google)Sigmoid Loss for Language Image Pre-Training
  3. arXiv (NeurIPS 2023)Visual Instruction Tuning
  4. LLaVA project pageLLaVA: Large Language and Vision Assistant
  5. GitHub (mlfoundations)OpenCLIP: An open source implementation of CLIP
  6. DistillMultimodal Neurons in Artificial Neural Networks
  7. Hugging FaceCompVis/stable-diffusion-v1-4 model card

探検を続けましょう

無料ニュースレター

毎日のAIブリーフィングを受け取る

毎週平日の朝に英語で書かれた3つの検証済みAIストーリー。無料で永続的、広告なし。

毎週平日に1通のメール。ワンクリックで購読解除。住所を販売または共有しません。

自分自身をテストしてください

Take the CLIP and Vision-Language Models quiz

すべての回答に即時フィードバック、合格後は検証可能なID付きの共有可能な証明書を取得。

クイズを開始する

無料AI教育をサポート。AI Understandingは501(c)(3)の非営利団体です — 広告なし、課金壁なし、常に。 寄付をする

よくある質問

What is CLIP and Vision-Language Models?

CLIP (Contrastive Language-Image Pre-training) is a 2021 OpenAI model that trains an image encoder and a text encoder to place matching pictures and captions close together in one shared vector space. That shared space lets software classify, search and filter images with plain-language descriptions, and CLIP-style encoders became the visual front end of many text-to-image and multimodal chat systems.

CLIPの背後にある中心的なアイデアは何ですか?

CLIP は画像とテキストの両方を 1 つの共有ベクトル空間にマッピングするため、それらの類似性を直接測定できます。

CLIPはどのようなトレーニングアプローチを使用していますか?

CLIP は対照的な目的を使用します。つまり、正しい画像とキャプションのペアが近くに引き寄せられ、不一致のペアが遠ざけられます。

What does zero-shot classification mean in the original CLIP transfer setup?

CLIP has substantial pretraining; zero-shot is scoped to the target classification evaluation.

CLIP は画像とキャプションが一致するかどうかをどのように測定しますか?

CLIP はそれぞれをベクトルにエンコードし、コサイン類似度を計算します。類似性が高いほど、意味上の一致がより密接であることを意味します。

CLIP はおよそどのくらいのデータでトレーニングされましたか?

CLIP は、インターネットから収集した約 4 億の画像とキャプションのペアから学習し、広範な視覚言語の知識を提供しました。