🚀 打破模態壁壘:使用多模態大語言模型進行通用嵌入學習
本項目提出了文本判別式知識蒸餾和硬負樣本增強指令調優等方法,提升了多模態大語言模型(MLLM)的嵌入能力,在MMEB排行榜上取得了優異成績。
🚀 快速開始
克隆倉庫並創建環境
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
代碼使用示例
import torch
from PIL import Image
from torch.nn import functional as F
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
base_model_path="DeepGlint-AI/UniME-LLaVA-1.6-7B"
img_prompt = "[INST] <image>\nSummary above image in one word: [/INST]"
text_prompt = "[INST] <sent>\nSummary above sentence in one word: [/INST]"
text = "A man is crossing the street with a red car parked nearby."
image_path = "figures/demo.png"
input_texts = text_prompt.replace('<sent>', text)
input_image_prompt = img_prompt
input_image = [Image.open(image_path)]
transform = LlavaNextProcessor.from_pretrained(base_model_path)
model = LlavaNextForConditionalGeneration.from_pretrained(base_model_path, device_map="cuda", torch_dtype=torch.float16, low_cpu_mem_usage=True)
transform.tokenizer.padding_side = "left"
transform.tokenizer.padding = True
inputs_text = transform(text=input_texts,
images=None,
return_tensors="pt",
padding=True)
for key in inputs_text: inputs_text[key] = inputs_text[key].to("cuda")
inputs_image = transform(text=input_image_prompt,
images=input_image,
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)
✨ 主要特性
文本判別式知識蒸餾
為了增強MLLM的嵌入能力,我們提出了文本判別式知識蒸餾方法。訓練過程包括解耦MLLM的大語言模型(LLM)組件,使用提示“用一個詞總結上述句子”處理文本,然後通過批量相似度分佈上的KL散度對齊學生模型(MLLM)和教師模型(NV-Embed V2)的嵌入。值得注意的是,在此過程中僅微調LLM組件,而其他所有參數保持凍結。
硬負樣本增強指令調優
之後,我們提出了硬負樣本增強指令調優方法,通過提高視覺敏感度、加強跨模態對齊和提升指令遵循能力來增強多模態系統。其核心有兩個關鍵創新:使用相似度閾值的假負樣本過濾機制,以消除誤導性樣本;以及自動硬負樣本採樣策略,選擇前k個相似但不匹配的示例以增加訓練難度。
📚 詳細文檔
項目信息
屬性 |
詳情 |
模型類型 |
圖像文本到文本 |
基礎模型 |
llava-hf/llava-v1.6-mistral-7b-hf |
訓練數據集 |
TIGER-Lab/MMEB-train |
評估指標 |
召回率 |
庫名稱 |
transformers |
許可證 |
MIT |
項目鏈接
🏡 項目主頁 | 📄 論文 | 💻 Github
項目成果
多樣化檢索
MMEB排行榜
UniME在使用336×336圖像分辨率進行訓練時,在MMEB排行榜上名列前茅。(截圖於2025年5月6日UTC+8 08:00捕獲。)
引用信息
如果您發現本倉庫有用,請使用以下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},
}