🚀 LLM2CLIP: 大規模言語モデルによるCLIPの能力限界の拡張
本論文では、大規模言語モデル(LLM)の力を活用してCLIPの潜在能力を引き出す新しいアプローチであるLLM2CLIPを提案します。対照学習を用いてキャプション空間でLLMを微調整することで、そのテキスト能力を出力埋め込みに抽出し、出力層のテキスト識別性を大幅に向上させます。そして、微調整されたLLMをCLIPのビジュアルエンコーダの強力な教師モデルとする効率的なトレーニングプロセスを設計します。LLMの導入により、従来のCLIPのテキストエンコーダのコンテキストウィンドウや能力の制限を受けることなく、より長く複雑なキャプションを取り入れることができます。実験の結果、このアプローチがクロスモーダルタスクにおいて大幅な改善をもたらすことが示されました。
✨ 主な機能
- 大規模言語モデル(LLM)を活用してCLIPの潜在能力を引き出し、出力層のテキスト識別性を向上させます。
- 微調整されたLLMをCLIPのビジュアルエンコーダの教師モデルとして使用し、効率的なトレーニングプロセスを実現します。
- 従来のCLIPのテキストエンコーダの制限を克服し、より長く複雑なキャプションを取り入れることができます。
- クロスモーダルタスクにおいて大幅な性能向上をもたらし、英語データのみで学習されたCLIPモデルを最先端のクロス言語モデルに変えます。
📦 インストール
このセクションでは、原ドキュメントにインストール手順が記載されていないため、省略します。
💻 使用例
基本的な使用法
画像埋め込み
from PIL import Image
from transformers import AutoModel
from transformers import CLIPImageProcessor
import torch
image_path = "CLIP.png"
model_name_or_path = "LLM2CLIP-Openai-L-14-336"
processor = CLIPImageProcessor.from_pretrained("openai/clip-vit-large-patch14-336")
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)
検索
from PIL import Image
from transformers import AutoModel, AutoConfig, AutoTokenizer
from transformers import CLIPImageProcessor
import torch
from llm2vec import LLM2Vec
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
processor = CLIPImageProcessor.from_pretrained("openai/clip-vit-large-patch14-336")
model_name_or_path = "microsoft/LLM2CLIP-Openai-L-14-336"
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)
📚 ドキュメント
論文情報
Weiquan Huang1*, Aoqi Wu1*, Yifan Yang2†, Xufang Luo2, Yuqing Yang2, Liang Hu1, Qi Dai2, Xiyang Dai2, Dongdong Chen2, Chong Luo2, Lili Qiu2
1Tongji Universiy, 2Microsoft Corporation
*Equal contribution
† Corresponding to: yifanyang@microsoft.com
リンク
モデル詳細
属性 |
详情 |
モデルタイプ |
ビジュアル基礎モデル、特徴バックボーン |
学習データセット |
CC3M、CC12M、YFCC15MおよびRecap-DataComp-1B(30Mサブセット) |
注意事項
⚠️ 重要提示
論文中に提示されたすべての結果は、PyTorchの重みを使用して評価されています。Hugging Face(hf)モデルを使用する場合、性能に差異が生じる可能性があります。
🔧 技術詳細
このセクションでは、原ドキュメントに技術的な詳細が記載されていないため、省略します。
📄 ライセンス
本プロジェクトは、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},
}