🚀 打破模态壁垒:使用多模态大语言模型进行通用嵌入学习
UniME项目致力于打破模态之间的障碍,利用多模态大语言模型实现通用嵌入学习。该项目在MMEB排行榜上取得了优异成绩,为多模态系统的发展提供了新的思路和方法。
项目信息
属性 |
详情 |
许可证 |
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的大语言模型(LLM)组件,并使用提示“用一个词总结上述句子”处理文本,然后通过KL散度在批量相似度分布上对齐学生模型(MLLM)和教师模型(NV-Embed V2)的嵌入。值得注意的是,在此过程中仅微调LLM组件,而其他所有参数保持冻结。
硬负样本增强指令调优
之后,我们提出了硬负样本增强指令调优方法,通过提高视觉敏感性、加强跨模态对齐和提升指令遵循能力来增强多模态系统。其核心有两个关键创新:一是使用相似度阈值的假负样本过滤机制,以消除误导性样本;二是自动硬负样本采样策略,选择前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|>\nSummary above image in one word: <|end|>\n<|assistant|>\n'
text_prompt = '<|user|>\n<sent>\nSummary above sentence in one word: <|end|>\n<|assistant|>\n'
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 = 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: ", Score)
📚 详细文档
多样化检索结果
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},
}