🚀 LLM2CLIP: 大規模言語モデルによるCLIPの能力限界の拡張
本論文では、大規模言語モデル(LLM)の力を活用してCLIPの潜在能力を引き出す新しいアプローチであるLLM2CLIPを提案しています。対照学習を用いてキャプション空間でLLMを微調整することで、そのテキスト処理能力を出力埋め込みに取り込み、出力層のテキスト識別性を大幅に向上させます。そして、微調整されたLLMをCLIPの視覚エンコーダの強力な教師モデルとする効率的な学習プロセスを設計しました。LLMの導入により、従来のCLIPテキストエンコーダのコンテキストウィンドウや能力の制限を受けることなく、より長く複雑なキャプションを取り入れることができます。実験の結果、このアプローチがクロスモーダルタスクで大幅な性能向上をもたらすことが示されました。この手法により、以前の最先端モデルであるEVA02の性能が長文と短文の両方の検索タスクで16.5%向上し、英語データのみで学習されたCLIPモデルを最先端のクロス言語モデルに変えることができました。さらに、Llava 1.5などのモデルとのマルチモーダル学習に組み込んだ場合、ほぼすべてのベンチマークでCLIPを上回り、包括的な性能向上を実証しました。
🚀 クイックスタート
本論文では、LLM2CLIPという新しいアプローチを提案しています。これは大規模言語モデル(LLM)の力を活用してCLIPの潜在能力を引き出すものです。以下に、モデルの使用方法の例を示します。
✨ 主な機能
- 大規模言語モデル(LLM)を用いてCLIPの能力限界を拡張します。
- 対照学習を用いた微調整により、出力層のテキスト識別性を向上させます。
- 長文と短文の検索タスクで性能を大幅に向上させます。
- クロス言語モデルとしての能力を発揮します。
- マルチモーダル学習においてCLIPを上回る性能を示します。
📦 インストール
本READMEには具体的なインストール手順が記載されていないため、このセクションをスキップします。
💻 使用例
基本的な使用法
Huggingface Version - Image Embeddings
from PIL import Image
from transformers import AutoModel
from transformers import CLIPImageProcessor
import torch
image_path = "CLIP.png"
model_name_or_path = "LLM2CLIP-Openai-B-16"
processor = CLIPImageProcessor.from_pretrained("openai/clip-vit-base-patch16")
model = AutoModel.from_pretrained(
model_name_or_path,
torch_dtype=torch.float16,
trust_remote_code=True).to('cuda').eval()
image = Image.open(image_path)
input_pixels = processor(images=image, return_tensors="pt").pixel_values.to('cuda')
with torch.no_grad(), torch.cuda.amp.autocast():
outputs = model.get_image_features(input_pixels)
Huggingface Version - Retrieval
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
from PIL import Image
import torch
from llm2vec import LLM2Vec
from transformers import AutoModel, AutoConfig, AutoTokenizer
from transformers import CLIPImageProcessor
processor = CLIPImageProcessor.from_pretrained("openai/clip-vit-base-patch16")
model_name_or_path = "microsoft/LLM2CLIP-Openai-B-16"
model = AutoModel.from_pretrained(
model_name_or_path,
torch_dtype=torch.bfloat16,
trust_remote_code=True).to('cuda').eval()
llm_model_name = 'microsoft/LLM2CLIP-Llama-3-8B-Instruct-CC-Finetuned'
config = AutoConfig.from_pretrained(
llm_model_name, trust_remote_code=True
)
llm_model = AutoModel.from_pretrained(llm_model_name, torch_dtype=torch.bfloat16, config=config, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(llm_model_name)
llm_model.config._name_or_path = 'meta-llama/Meta-Llama-3-8B-Instruct'
l2v = LLM2Vec(llm_model, tokenizer, pooling_mode="mean", max_length=512, doc_max_length=512)
captions = ["a diagram", "a dog", "a cat"]
image_path = "CLIP.png"
image = Image.open(image_path)
input_pixels = processor(images=image, return_tensors="pt").pixel_values.to('cuda')
text_features = l2v.encode(captions, convert_to_tensor=True).to('cuda')
with torch.no_grad(), torch.cuda.amp.autocast():
image_features = model.get_image_features(input_pixels)
text_features = model.get_text_features(text_features)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("Label probs:", text_probs)
📚 ドキュメント
LLM2CLIP性能
> ⚠️ **重要提示**
>
> 論文に示されたすべての結果は、PyTorchの重みを使用して評価されています。Hugging Face (hf) モデルを使用する場合、性能に違いが生じる可能性があります。
モデル詳細
属性 |
详情 |
モデルタイプ |
ビジョン基礎モデル、特徴バックボーン |
事前学習データセット |
CC3M、CC12M、YFCC15M、およびRecap-DataComp-1B(30Mサブセット) |
🔧 技術詳細
本READMEには具体的な技術詳細が記載されていないため、このセクションをスキップします。
📄 ライセンス
本プロジェクトはApache-2.0ライセンスの下で公開されています。
BibTeX & Citation
@misc{huang2024llm2clippowerfullanguagemodel,
title={LLM2CLIP: Powerful Language Model Unlock Richer Visual Representation},
author={Weiquan Huang and Aoqi Wu and Yifan Yang and Xufang Luo and Yuqing Yang and Liang Hu and Qi Dai and Xiyang Dai and Dongdong Chen and Chong Luo and Lili Qiu},
year={2024},
eprint={2411.04997},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2411.04997},
}