Llave 0.5B
LLaVE是基於LLaVA-OneVision-0.5B模型的多模態嵌入模型,參數規模為0.5B,能夠對文本、圖像、多圖像和視頻進行嵌入。
下載量 2,897
發布時間 : 2/6/2025
模型概述
LLaVE是一個多模態嵌入模型,能夠處理文本、圖像和視頻數據,支持句子相似度計算、零樣本圖像分類等任務。
模型特點
多模態嵌入
能夠同時對文本、圖像和視頻數據進行嵌入處理
高效性能
僅使用少量參數和訓練數據就在MMEB排行榜上取得優異表現
零樣本遷移能力
在圖像-文本數據上訓練,但能零樣本泛化到文本-視頻檢索任務
模型能力
文本嵌入
圖像嵌入
視頻嵌入
句子相似度計算
零樣本圖像分類
跨模態檢索
使用案例
圖像檢索
基於文本的圖像搜索
根據文本描述檢索相關圖像
在MMEB評估中表現優異
跨模態檢索
文本到視頻檢索
根據文本描述檢索相關視頻片段
零樣本情況下表現出強大性能
🚀 LLaVE-0.5B
LLaVE-0.5B 是一個參數為 0.5B 的多模態嵌入模型,基於 LLaVA-OneVision-0.5B 模型構建,具有 4K 令牌的上下文窗口。它能夠對文本、圖像、多圖像和視頻進行嵌入處理,在 MMEB 排行榜上取得了優異成績,還能在零樣本的情況下泛化到文本 - 視頻檢索任務。
🚀 快速開始
首先克隆我們的 GitHub 倉庫:
git clone https://github.com/DeepLearnXMU/LLaVE
cd LLaVE
pip install -e ".[train]"
我們提供了使用該模型的簡單嵌入過程。更多詳細信息,請參考 Github。
# pip install git+https://github.com/DeepLearnXMU/LLaVE
import torch
import copy
from PIL import Image
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
from llava.conversation import conv_templates
from llava.model.builder import load_pretrained_model
from llava.mm_utils import tokenizer_image_token, process_images
pretrained = "zhibinlan/LLaVE-0.5B"
model_name = "llava_qwen"
device = "cuda"
device_map = "auto"
tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, device_map=device_map) # Add any other thing you want to pass in llava_model_args
model.eval()
# Image + Text -> Text
image = Image.open("figures/example.jpg")
image_tensor = process_images([image], image_processor, model.config)
image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
conv_template = "qwen_1_5" # Make sure you use correct chat template for different models
question = DEFAULT_IMAGE_TOKEN + " Represent the given image with the following question: What is in the image"
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], question)
conv.append_message(conv.roles[1], "\n")
prompt_question = conv.get_prompt()
input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
attention_mask=input_ids.ne(tokenizer.pad_token_id)
image_sizes = [image.size]
query_embed = model.encode_multimodal_embeddings(input_ids, attention_mask=attention_mask,images=image_tensor, image_sizes=image_sizes)
target_string = "A cat and a dog"
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], target_string)
conv.append_message(conv.roles[1], "\n")
target_string = conv.get_prompt()
target_input_ids = tokenizer(target_string, return_tensors="pt").input_ids.to(device)
attention_mask=target_input_ids.ne(tokenizer.pad_token_id)
target_embed = model.encode_multimodal_embeddings(target_input_ids, attention_mask=attention_mask)
print("A cat and a dog similarity score: ", query_embed @ target_embed.T)
# 0.5B: A cat and a dog similarity score: tensor([[0.4802]]
neg_string = "A cat and a tiger"
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], neg_string)
conv.append_message(conv.roles[1], "\n")
neg_string = conv.get_prompt()
neg_input_ids = tokenizer(neg_string, return_tensors="pt").input_ids.to(device)
attention_mask=neg_input_ids.ne(tokenizer.pad_token_id)
neg_embed = model.encode_multimodal_embeddings(neg_input_ids, attention_mask=attention_mask)
print("A cat and a tiger similarity score: ", query_embed @ neg_embed.T)
# 0.5B: A cat and a tiger similarity score: tensor([[0.3413]]
# Text -> Image
pos_string = "Find me an everyday image that matches the given caption: A cat and a dog."
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], pos_string)
conv.append_message(conv.roles[1], "\n")
pos_string = conv.get_prompt()
pos_input_ids = tokenizer(pos_string, return_tensors="pt").input_ids.to(device)
attention_mask=pos_input_ids.ne(tokenizer.pad_token_id)
pos_query_embed = model.encode_multimodal_embeddings(pos_input_ids, attention_mask=attention_mask)
target = DEFAULT_IMAGE_TOKEN + " Represent the given image."
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], target)
conv.append_message(conv.roles[1], "\n")
prompt_target = conv.get_prompt()
target_input_ids = tokenizer_image_token(prompt_target, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
attention_mask=target_input_ids.ne(tokenizer.pad_token_id)
target_image_sizes = [image.size]
target_embed = model.encode_multimodal_embeddings(target_input_ids, attention_mask=attention_mask,images=image_tensor, image_sizes=target_image_sizes)
print("A cat and a dog image similarity score: ", pos_query_embed @ target_embed.T)
# 0.5B: A cat and a dog similarity score: tensor([[0.3992]]
neg_string = "Find me an everyday image that matches the given caption: A cat and a tiger."
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], neg_string)
conv.append_message(conv.roles[1], "\n")
neg_string = conv.get_prompt()
neg_input_ids = tokenizer(neg_string, return_tensors="pt").input_ids.to(device)
attention_mask=neg_input_ids.ne(tokenizer.pad_token_id)
neg_query_embed = model.encode_multimodal_embeddings(neg_input_ids, attention_mask=attention_mask)
print("A cat and a tiger image similarity score: ", neg_query_embed @ target_embed.T)
# 0.5B: A cat and a dog similarity score: tensor([[0.3354]]
✨ 主要特性
- 多模態嵌入能力:該模型能夠對文本、圖像、多圖像和視頻進行嵌入處理。
- 優異的性能表現:在 MMEB 排行榜上取得了優異成績,僅使用少量數據和 662K 訓練對。
- 零樣本泛化能力:雖然模型是在圖像 - 文本數據上訓練的,但它可以在零樣本的情況下泛化到文本 - 視頻檢索任務,並取得了不錯的性能。
📦 安裝指南
克隆 GitHub 倉庫並安裝依賴:
git clone https://github.com/DeepLearnXMU/LLaVE
cd LLaVE
pip install -e ".[train]"
💻 使用示例
基礎用法
以下代碼展示瞭如何使用該模型進行圖像 + 文本到文本的嵌入和相似度計算:
# pip install git+https://github.com/DeepLearnXMU/LLaVE
import torch
import copy
from PIL import Image
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
from llava.conversation import conv_templates
from llava.model.builder import load_pretrained_model
from llava.mm_utils import tokenizer_image_token, process_images
pretrained = "zhibinlan/LLaVE-0.5B"
model_name = "llava_qwen"
device = "cuda"
device_map = "auto"
tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, device_map=device_map) # Add any other thing you want to pass in llava_model_args
model.eval()
# Image + Text -> Text
image = Image.open("figures/example.jpg")
image_tensor = process_images([image], image_processor, model.config)
image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
conv_template = "qwen_1_5" # Make sure you use correct chat template for different models
question = DEFAULT_IMAGE_TOKEN + " Represent the given image with the following question: What is in the image"
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], question)
conv.append_message(conv.roles[1], "\n")
prompt_question = conv.get_prompt()
input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
attention_mask=input_ids.ne(tokenizer.pad_token_id)
image_sizes = [image.size]
query_embed = model.encode_multimodal_embeddings(input_ids, attention_mask=attention_mask,images=image_tensor, image_sizes=image_sizes)
target_string = "A cat and a dog"
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], target_string)
conv.append_message(conv.roles[1], "\n")
target_string = conv.get_prompt()
target_input_ids = tokenizer(target_string, return_tensors="pt").input_ids.to(device)
attention_mask=target_input_ids.ne(tokenizer.pad_token_id)
target_embed = model.encode_multimodal_embeddings(target_input_ids, attention_mask=attention_mask)
print("A cat and a dog similarity score: ", query_embed @ target_embed.T)
# 0.5B: A cat and a dog similarity score: tensor([[0.4802]]
neg_string = "A cat and a tiger"
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], neg_string)
conv.append_message(conv.roles[1], "\n")
neg_string = conv.get_prompt()
neg_input_ids = tokenizer(neg_string, return_tensors="pt").input_ids.to(device)
attention_mask=neg_input_ids.ne(tokenizer.pad_token_id)
neg_embed = model.encode_multimodal_embeddings(neg_input_ids, attention_mask=attention_mask)
print("A cat and a tiger similarity score: ", query_embed @ neg_embed.T)
# 0.5B: A cat and a tiger similarity score: tensor([[0.3413]]
高級用法
以下代碼展示瞭如何使用該模型進行文本到圖像的嵌入和相似度計算:
# Text -> Image
pos_string = "Find me an everyday image that matches the given caption: A cat and a dog."
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], pos_string)
conv.append_message(conv.roles[1], "\n")
pos_string = conv.get_prompt()
pos_input_ids = tokenizer(pos_string, return_tensors="pt").input_ids.to(device)
attention_mask=pos_input_ids.ne(tokenizer.pad_token_id)
pos_query_embed = model.encode_multimodal_embeddings(pos_input_ids, attention_mask=attention_mask)
target = DEFAULT_IMAGE_TOKEN + " Represent the given image."
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], target)
conv.append_message(conv.roles[1], "\n")
prompt_target = conv.get_prompt()
target_input_ids = tokenizer_image_token(prompt_target, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
attention_mask=target_input_ids.ne(tokenizer.pad_token_id)
target_image_sizes = [image.size]
target_embed = model.encode_multimodal_embeddings(target_input_ids, attention_mask=attention_mask,images=image_tensor, image_sizes=target_image_sizes)
print("A cat and a dog image similarity score: ", pos_query_embed @ target_embed.T)
# 0.5B: A cat and a dog similarity score: tensor([[0.3992]]
neg_string = "Find me an everyday image that matches the given caption: A cat and a tiger."
conv = copy.deepcopy(conv_templates[conv_template])
conv.append_message(conv.roles[0], neg_string)
conv.append_message(conv.roles[1], "\n")
neg_string = conv.get_prompt()
neg_input_ids = tokenizer(neg_string, return_tensors="pt").input_ids.to(device)
attention_mask=neg_input_ids.ne(tokenizer.pad_token_id)
neg_query_embed = model.encode_multimodal_embeddings(neg_input_ids, attention_mask=attention_mask)
print("A cat and a tiger image similarity score: ", neg_query_embed @ target_embed.T)
# 0.5B: A cat and a dog similarity score: tensor([[0.3354]]
📚 詳細文檔
模型概述
LLaVE 模型是基於 LLaVA-OneVision-0.5B 模型的 0.5B 參數多模態嵌入模型,上下文窗口為 4K 令牌。
訓練/評估數據
- 訓練數據:https://huggingface.co/datasets/TIGER-Lab/MMEB-train
- 評估數據:https://huggingface.co/datasets/TIGER-Lab/MMEB-eval
預期用途
該模型能夠對文本、圖像、多圖像和視頻進行嵌入處理。
MMEB 排行榜
我們僅使用少量數據就在 MMEB 排行榜上取得了領先排名。
模型性能
LLaVE-0.5B 在 MMEB 上使用較少的參數和 662K 訓練對取得了優異的性能。
儘管 LLaVE 是在圖像 - 文本數據上訓練的,但它可以在零樣本的情況下泛化到文本 - 視頻檢索任務,並取得了不錯的性能,展示了其在其他嵌入任務上的顯著遷移潛力。

🔧 技術細節
硬件與軟件
- GPU:8 * Nvidia A100 (40G)(用於全模型訓練)
- 編排工具:Huggingface Trainer
- 神經網絡框架:PyTorch
📄 許可證
本項目採用 Apache-2.0 許可證。
📄 引用
@article{lan2025llave,
title={LLaVE: Large Language and Vision Embedding Models with Hardness-Weighted Contrastive Learning},
author={Lan, Zhibin and Niu, Liqiang and Meng, Fandong and Zhou, Jie and Su, Jinsong},
journal={arXiv preprint arXiv:2503.04812},
year={2025}
}
Codebert Base
CodeBERT是一個面向編程語言與自然語言的預訓練模型,基於RoBERTa架構,支持代碼搜索和代碼生成文檔等功能。
多模態融合
C
microsoft
1.6M
248
Llama 4 Scout 17B 16E Instruct
其他
Llama 4 Scout是Meta開發的多模態AI模型,採用混合專家架構,支持12種語言的文本和圖像交互,具有17B激活參數和109B總參數。
多模態融合
Transformers 支持多種語言

L
meta-llama
817.62k
844
Unixcoder Base
Apache-2.0
UniXcoder是一個統一的多模態預訓練模型,利用代碼註釋和抽象語法樹等多模態數據預訓練代碼表示。
多模態融合
Transformers 英語

U
microsoft
347.45k
51
TITAN
TITAN是一個多模態全切片基礎模型,通過視覺自監督學習和視覺-語言對齊進行預訓練,用於病理學圖像分析。
多模態融合
Safetensors 英語
T
MahmoodLab
213.39k
37
Qwen2.5 Omni 7B
其他
Qwen2.5-Omni 是一個端到端的多模態模型,能夠感知文本、圖像、音頻和視頻等多種模態,並以流式方式生成文本和自然語音響應。
多模態融合
Transformers 英語

Q
Qwen
206.20k
1,522
Minicpm O 2 6
MiniCPM-o 2.6是一款手機端運行的GPT-4o級多模態大模型,支持視覺、語音與直播流處理
多模態融合
Transformers 其他

M
openbmb
178.38k
1,117
Llama 4 Scout 17B 16E Instruct
其他
Llama 4 Scout是Meta推出的17B參數/16專家混合的多模態AI模型,支持12種語言和圖像理解,具有行業領先性能。
多模態融合
Transformers 支持多種語言

L
chutesai
173.52k
2
Qwen2.5 Omni 3B
其他
Qwen2.5-Omni是一款端到端多模態模型,能夠感知文本、圖像、音頻和視頻等多種模態信息,並以流式方式同步生成文本和自然語音響應。
多模態融合
Transformers 英語

Q
Qwen
48.07k
219
One Align
MIT
Q-Align是一個多任務視覺評估模型,專注於圖像質量評估(IQA)、美學評估(IAA)和視頻質量評估(VQA),在ICML2024上發表。
多模態融合
Transformers

O
q-future
39.48k
25
Biomedvlp BioViL T
MIT
BioViL-T是一個專注於分析胸部X光片和放射學報告的視覺語言模型,通過時序多模態預訓練提升性能。
多模態融合
Transformers 英語

B
microsoft
26.39k
35
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98