Dse Qwen2 2b Mrl V1
模型概述
該模型採用文檔截圖嵌入(DSE)方法,以原始視覺格式捕獲文檔,保留所有信息(如文本、圖像和佈局),避免繁瑣的解析和潛在的信息丟失。旨在為文本、PDF文檔、網頁和幻燈片檢索提供通用的嵌入模型。
模型特點
原始視覺格式處理
直接處理文檔截圖,保留原始佈局、文本和圖像信息
靈活的表示維度
支持調整輸出嵌入維度以平衡效果與效率
靈活的輸入尺寸
可根據GPU資源調整輸入圖像尺寸
多語言支持
支持英文和法文文檔處理
模型能力
文檔截圖嵌入
密集向量檢索
跨模態文檔理解
多語言文檔處理
使用案例
文檔檢索
學術論文檢索
通過論文截圖檢索相關文獻
在ViDoRE排行榜上實現85.8的nDCG@5
企業文檔管理
快速檢索PDF、PPT等企業文檔
跨模態搜索
圖文混合檢索
同時處理文檔中的文本和視覺信息進行檢索
🚀 DSE-QWen2-2b-MRL-V1
DSE-QWen2-2b-MRL-V1 是一個雙編碼器模型,旨在將文檔截圖編碼為密集向量,用於文檔檢索。文檔截圖嵌入(DSE)方法以原始視覺格式捕獲文檔,保留文本、圖像和佈局等所有信息,從而避免了繁瑣的解析過程和潛在的信息丟失。DSE 旨在為文本、PDF 文檔、網頁和幻燈片檢索提供一個通用的嵌入模型。
例如,DSE-QWen2-2b-MRL-V1 在 ViDoRE 排行榜上的 nDCG@5 達到了 85.8。
🚀 快速開始
模型信息
屬性 | 詳情 |
---|---|
模型類型 | 雙編碼器模型,用於視覺文檔檢索 |
訓練數據 | Tevatron/docmatix-ir、HuggingFaceM4/Docmatix、Tevatron/msmarco-passage-aug、vidore/colpali_train_set、Tevatron/wiki-ss-nq |
基礎模型 | Qwen/Qwen2-VL-2B-Instruct |
許可證 | Apache-2.0 |
重要提示
⚠️ 重要提示
如果輸入圖像較大,QWen 視覺編碼器可能會佔用較高的 GPU 內存。請根據 GPU 資源調整
'resized_height':680 , 'resized_width':680
以適應顯存。
💻 使用示例
基礎用法
加載模型和處理器
import torch
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
from qwen_vl_utils import process_vision_info
min_pixels = 1*28*28
max_pixels = 2560*28*28
processor = AutoProcessor.from_pretrained("MrLight/dse-qwen2-2b-mrl-v1", min_pixels=min_pixels, max_pixels=max_pixels)
model = Qwen2VLForConditionalGeneration.from_pretrained('MrLight/dse-qwen2-2b-mrl-v1', attn_implementation="flash_attention_2", torch_dtype=torch.bfloat16).to('cuda:0').eval()
processor.tokenizer.padding_side = "left"
model.padding_side = "left"
def get_embedding(last_hidden_state: torch.Tensor, dimension: int) -> torch.Tensor:
reps = last_hidden_state[:, -1]
reps = torch.nn.functional.normalize(reps[:, :dimension], p=2, dim=-1)
return reps
編碼文本查詢
from PIL import Image
queries = ["Where can we see Llama?", "What is the LLaMA AI model?"]
query_messages = []
for query in queries:
message = [
{
'role': 'user',
'content': [
{'type': 'image', 'image': Image.new('RGB', (28, 28)), 'resized_height':1 , 'resized_width':1}, # need a dummy image here for an easier process.
{'type': 'text', 'text': f'Query: {query}'},
]
}
]
query_messages.append(message)
query_texts = [
processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True) + "<|endoftext|>"
for msg in query_messages
]
query_image_inputs, query_video_inputs = process_vision_info(query_messages)
query_inputs = processor(text=query_texts, images=query_image_inputs, videos=query_video_inputs, padding='longest', return_tensors='pt').to('cuda:0')
cache_position = torch.arange(0, len(query_texts))
query_inputs = model.prepare_inputs_for_generation(**query_inputs, cache_position=cache_position, use_cache=False)
with torch.no_grad():
output = model(**query_inputs, return_dict=True, output_hidden_states=True)
query_embeddings = get_embedding(output.hidden_states[-1], 1536) # adjust dimensionality for efficiency trade-off, e.g. 512
編碼文檔截圖
import requests
from io import BytesIO
# URLs of the images
url1 = "https://huggingface.co/Tevatron/dse-phi3-docmatix-v2/resolve/main/animal-llama.png"
url2 = "https://huggingface.co/Tevatron/dse-phi3-docmatix-v2/resolve/main/meta-llama.png"
# Download and open images
response1 = requests.get(url1)
response2 = requests.get(url2)
doc_image1 = Image.open(BytesIO(response1.content))
doc_image2 = Image.open(BytesIO(response2.content))
doc_images = [doc_image1, doc_image2]
doc_messages = []
for doc in doc_images:
message = [
{
'role': 'user',
'content': [
{'type': 'image', 'image': doc}, #'resized_height':680 , 'resized_width':680} # adjust the image size for efficiency trade-off
{'type': 'text', 'text': 'What is shown in this image?'}
]
}
]
doc_messages.append(message)
doc_texts = [
processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True) + "<|endoftext|>"
for msg in doc_messages
]
doc_image_inputs, doc_video_inputs = process_vision_info(doc_messages)
doc_inputs = processor(text=doc_texts, images=doc_image_inputs, videos=doc_video_inputs, padding='longest', return_tensors='pt').to('cuda:0')
cache_position = torch.arange(0, len(doc_texts))
doc_inputs = model.prepare_inputs_for_generation(**doc_inputs, cache_position=cache_position, use_cache=False)
with torch.no_grad():
output = model(**doc_inputs, return_dict=True, output_hidden_states=True)
doc_embeddings = get_embedding(output.hidden_states[-1], 1536) # adjust dimensionality for efficiency trade-off e.g. 512
計算相似度
from torch.nn.functional import cosine_similarity
num_queries = query_embeddings.size(0)
num_passages = doc_embeddings.size(0)
for i in range(num_queries):
query_embedding = query_embeddings[i].unsqueeze(0)
similarities = cosine_similarity(query_embedding, doc_embeddings)
print(f"Similarities for Query {i+1}: {similarities.cpu().float().numpy()}")
編碼文檔文本
此 DSE 檢查點使用 Tevatron/msmarco-passage-aug
進行預熱,因此該模型也可以有效地將文檔編碼為文本輸入。
doc_texts = [
"The llama (/ˈlɑːmə/; Spanish pronunciation: [ˈʎama] or [ˈʝama]) (Lama glama) is a domesticated South American camelid, widely used as a meat and pack animal by Andean cultures since the pre-Columbian era.",
"Llama (acronym for Large Language Model Meta AI, and formerly stylized as LLaMA) is a family of autoregressive large language models (LLMs) released by Meta AI starting in February 2023.[2][3] The latest version is Llama 3.1, released in July 2024.[4]"
]
doc_messages = []
for doc in doc_texts:
message = [
{
'role': 'user',
'content': [
{'type': 'image', 'image': Image.new('RGB', (28, 28)), 'resized_height':1 , 'resized_width':1}, # need a dummy image here for an easier process.
{'type': 'text', 'text': f'Document: {doc}'}
]
}
]
doc_messages.append(message)
doc_texts = [
processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True) + "<|endoftext|>"
for msg in doc_messages
]
doc_image_inputs, doc_video_inputs = process_vision_info(doc_messages)
doc_inputs = processor(text=doc_texts, images=doc_image_inputs, videos=doc_video_inputs, padding='longest', return_tensors='pt').to('cuda:0')
cache_position = torch.arange(0, len(doc_texts))
doc_inputs = model.prepare_inputs_for_generation(**doc_inputs, cache_position=cache_position, use_cache=False)
with torch.no_grad():
output = model(**doc_inputs, return_dict=True, output_hidden_states=True)
doc_embeddings = get_embedding(output.hidden_states[-1], 1536) # adjust dimensionality for efficiency trade-off e.g. 512
for i in range(num_queries):
query_embedding = query_embeddings[i].unsqueeze(0)
similarities = cosine_similarity(query_embedding, doc_embeddings)
print(f"Similarities for Query {i+1}: {similarities.cpu().float().numpy()}")
引用
如果您發現此檢查點很有幫助,請考慮引用 QWen2、Docmatix、ViDoRe 和我們的 DSE 工作。
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