🚀 モダリティの壁を打ち破る:マルチモーダルLLMによる普遍的な埋め込み学習
本プロジェクトは、マルチモーダル大規模言語モデル(MLLM)を用いた普遍的な埋め込み学習に焦点を当て、モダリティ間の障壁を克服することを目指しています。これにより、画像とテキストの情報を効果的に統合し、高い性能を達成します。
🚀 クイックスタート
git clone https://github.com/deepglint/UniME.git
cd UniME
conda create -n uniME python=3.10 -y
conda activate uniME
pip install -r requirements.txt
pip install transformers==4.49.0
基本的な使用法
import torch
from PIL import Image
from torch.nn import functional as F
from transformers import AutoProcessor, LlavaOnevisionForConditionalGeneration
def appply_chat_template(image=None, text=None):
if image != None:
conversation_image = [{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": "Summary above image in one word:\n"},
],
}]
elif text!= None:
conversation_image = [{
"role": "user",
"content": [
{"type": "text", "text": f"{text}\nSummary above sentence in one word:\n"},
],
}]
return conversation_image
base_model_path="DeepGlint-AI/UniME-LLaVA-OneVision-7B"
text = "A man is crossing the street with a red car parked nearby."
image_path = "figures/demo.png"
input_image = [Image.open(image_path)]
transform = AutoProcessor.from_pretrained(base_model_path, trust_remote_code=True)
model = LlavaOnevisionForConditionalGeneration.from_pretrained(base_model_path,device_map="cuda", trust_remote_code=True, torch_dtype=torch.float16)
transform.tokenizer.padding_side = "left"
transform.tokenizer.padding = True
inputs_text = transform.apply_chat_template([appply_chat_template(text = text)],
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
padding=True).to("cuda")
inputs_image = transform.apply_chat_template([appply_chat_template(image = input_image)],
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
padding=True).to("cuda")
with torch.no_grad():
emb_text = model(**inputs_text, output_hidden_states=True, return_dict=True).hidden_states[-1][:, -1, :]
emb_image = model(**inputs_image, output_hidden_states=True, return_dict=True).hidden_states[-1][:, -1, :]
emb_text = F.normalize(emb_text, dim=-1)
emb_image = F.normalize(emb_image, dim=-1)
Score = emb_image @ emb_text.T
print("Score: ", Score.item())
✨ 主な機能
テキスト識別知識蒸留
MLLMの埋め込み能力を向上させるために、テキスト識別知識蒸留を提案しています。学習プロセスでは、MLLMのLLMコンポーネントを分離し、「上記の文章を一言で要約する」というプロンプトでテキストを処理し、学生(MLLM)と教師(NV-Embed V2)の埋め込みをバッチ単位の類似度分布でKLダイバージェンスを用いてアライメントさせます。このプロセスでは、LLMコンポーネントのみを微調整し、他のパラメータは固定したままです。
ハードネガティブ強化命令微調整
ハードネガティブ強化命令微調整により、視覚的な感度を向上させ、クロスモーダルアライメントを強化し、命令追従能力を向上させることができます。この方法の核心は、類似度閾値を使用して誤ったネガティブサンプルをフィルタリングする機構と、トップkの類似しているが一致しないサンプルを選択して学習の難易度を上げる自動ハードネガティブサンプリング戦略です。
📚 ドキュメント
多様な検索結果
MMEBにおける結果
📄 ライセンス
本プロジェクトはMITライセンスの下で公開されています。
📚 引用
もしこのリポジトリが役に立った場合は、以下のBibTeXエントリを使用して引用してください。
@misc{gu2025breakingmodalitybarrieruniversal,
title={Breaking the Modality Barrier: Universal Embedding Learning with Multimodal LLMs},
author={Tiancheng Gu and Kaicheng Yang and Ziyong Feng and Xingjun Wang and Yanzhao Zhang and Dingkun Long and Yingda Chen and Weidong Cai and Jiankang Deng},
year={2025},
eprint={2504.17432},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2504.17432},
}
関連情報
著者
モデル情報
属性 |
详情 |
モデルタイプ |
image-text-to-text |
ベースモデル |
llava-hf/llava-onevision-qwen2-7b-ov-hf |
ライブラリ名 |
transformers |
データセット |
TIGER-Lab/MMEB-train |
評価指標 |
recall |