许可证: mit
数据集:
- TIGER-Lab/MMEB-train
语言:
- 英语
基础模型:
- microsoft/Phi-3.5-vision-instruct
库名称: transformers
标签:
- 检索
- 多模态
- 嵌入
管道标签: 图像-文本到文本
打破模态壁垒:基于多模态大模型的通用嵌入学习
顾天城*,
杨凯程*,
冯子勇,
王兴俊,
张彦钊,
龙定坤,
陈英达,
蔡卫东,
邓健康
🏡 项目主页 | 📄 论文 | 💻 GitHub
UniME 使用336×336图像分辨率训练,在MMEB排行榜上位列第一。(截图时间为2025年5月6日UTC+8时间08:00。)
💡 亮点
为了增强多模态大模型(MLLM)的嵌入能力,我们提出了文本判别性知识蒸馏方法。训练过程包括解耦MLLM的语言模型组件,并使用提示“用一句话总结上述内容”处理文本,然后通过KL散度对齐学生模型(MLLM)和教师模型(NV-Embed V2)在批次相似度分布上的嵌入。值得注意的是,此过程中仅微调语言模型组件,其余参数均保持冻结。
随后,我们提出硬负样本增强的指令调优方法,通过提升视觉敏感性、加强跨模态对齐和增强指令跟随能力来优化多模态系统。其核心包含两项关键创新:一是使用相似度阈值的假负样本过滤机制,以消除误导性样本;二是自动硬负样本采样策略,选择前k个相似但不匹配的样本以增加训练难度。
🧭 快速开始
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 AutoProcessor, AutoModelForCausalLM
base_model_path="DeepGlint-AI/UniME-Phi3.5-V-4.2B"
img_prompt = '<|user|>\n<|image_1|>\n用一句话总结上图:<|end|>\n<|assistant|>\n'
text_prompt = '<|user|>\n<sent>\n用一句话总结上述内容:<|end|>\n<|assistant|>\n'
text = "一名男子正在过马路,旁边停着一辆红色汽车。"
image_path = "figures/demo.png"
input_texts = text_prompt.replace('<sent>', text)
input_image_prompt = img_prompt
input_image = [Image.open(image_path)]
transform = AutoProcessor.from_pretrained(base_model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(base_model_path,device_map="cuda", trust_remote_code=True,torch_dtype=torch.float16, _attn_implementation='flash_attention_2')
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)
🔢 结果
多样化检索
MMEB
📖 引用
如果本仓库对您有帮助,请使用以下BibTeX条目引用。
@misc{gu2025breakingmodalitybarrieruniversal,
title={打破模态壁垒:基于多模态大模型的通用嵌入学习},
author={顾天城 and 杨凯程 and 冯子勇 and 王兴俊 and 张彦钊 and 龙定坤 and 陈英达 and 蔡卫东 and 邓健康},
year={2025},
eprint={2504.17432},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2504.17432},
}