🚀 MonoQwen2-VL-v0.1
MonoQwen2-VL-v0.1は、Qwen2-VL-2B からLoRAを用いて微調整されたマルチモーダルなリランカーです。このモデルは、MonoT5 の目的を使用して、画像とクエリのポイントワイズな関連性を評価するように最適化されています。つまり、画像とクエリのペアをビジュアル言語モデル(VLM)のプロンプトに入力すると、画像がクエリに関連する場合は「True」を、関連しない場合は「False」を生成するように設計されています。推論時には、2つのトークンのロジットを比較することで関連性スコアを取得でき、このスコアを使用して、一次検索器(DSEやColPaliなど)が生成した候補をリランクしたり、閾値を使用してフィルタリングしたりすることができます。
このモデルは、DSEを使用してマイニングされた負例を含む ColPaliトレーニングセット を使用してトレーニングされています。
🚀 クイックスタート
このモデルを使用して、ユーザーのクエリに対して単一の画像をリランクする簡単な例を以下に示します。
import torch
from PIL import Image
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
model = Qwen2VLForConditionalGeneration.from_pretrained(
"lightonai/MonoQwen2-VL-v0.1",
device_map="auto",
)
query = "What is ColPali?"
image_path = "your/path/to/image.png"
image = Image.open(image_path)
prompt = (
"Assert the relevance of the previous image document to the following query, "
"answer True or False. The query is: {query}"
).format(query=query)
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": prompt},
],
}
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=text, images=image, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model(**inputs)
logits_for_last_token = outputs.logits[:, -1, :]
true_token_id = processor.tokenizer.convert_tokens_to_ids("True")
false_token_id = processor.tokenizer.convert_tokens_to_ids("False")
relevance_score = torch.softmax(logits_for_last_token[:, [true_token_id, false_token_id]], dim=-1)
true_prob = relevance_score[0, 0].item()
false_prob = relevance_score[0, 1].item()
print(f"True probability: {true_prob:.4f}, False probability: {false_prob:.4f}")
この例では、モデルを使用して画像とクエリの関連性を評価する方法を示しています。画像が関連する("True")または関連しない("False")確率を出力します。
⚠️ 重要提示
この例では、環境に peft
をインストールする必要があります (pip install peft
)。peft
を使用したくない場合は、元のQwen2-VL-2Bモデルで model.load_adapter
load_adapter を使用することができます。
💻 使用例
基本的な使用法
import torch
from PIL import Image
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
model = Qwen2VLForConditionalGeneration.from_pretrained(
"lightonai/MonoQwen2-VL-v0.1",
device_map="auto",
)
query = "What is ColPali?"
image_path = "your/path/to/image.png"
image = Image.open(image_path)
prompt = (
"Assert the relevance of the previous image document to the following query, "
"answer True or False. The query is: {query}"
).format(query=query)
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": prompt},
],
}
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=text, images=image, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model(**inputs)
logits_for_last_token = outputs.logits[:, -1, :]
true_token_id = processor.tokenizer.convert_tokens_to_ids("True")
false_token_id = processor.tokenizer.convert_tokens_to_ids("False")
relevance_score = torch.softmax(logits_for_last_token[:, [true_token_id, false_token_id]], dim=-1)
true_prob = relevance_score[0, 0].item()
false_prob = relevance_score[0, 1].item()
print(f"True probability: {true_prob:.4f}, False probability: {false_prob:.4f}")
📚 ドキュメント
性能指標
このモデルは、ViDoReベンチマーク で評価されています。具体的には、MrLight_dse-qwen2-2b-mrl-v1 を使用して10個の要素を検索し、それらをリランクしています。以下の表は、ndcg@5
スコアをまとめたものです。
データセット |
MrLight_dse-qwen2-2b-mrl-v1 |
MonoQwen2-VL-v0.1 リランク |
vidore/arxivqa_test_subsampled |
85.6 |
89.0 |
vidore/docvqa_test_subsampled |
57.1 |
59.7 |
vidore/infovqa_test_subsampled |
88.1 |
93.2 |
vidore/tabfquad_test_subsampled |
93.1 |
96.0 |
vidore/shiftproject_test |
82.0 |
93.0 |
vidore/syntheticDocQA_artificial_intelligence_test |
97.5 |
100.0 |
vidore/syntheticDocQA_energy_test |
92.9 |
97.7 |
vidore/syntheticDocQA_government_reports_test |
96.0 |
98.0 |
vidore/syntheticDocQA_healthcare_industry_test |
96.4 |
99.3 |
vidore/tatdqa_test |
69.4 |
79.0 |
平均 |
85.8 |
90.5 |
📄 ライセンス
このLoRAモデルは、Apache 2.0ライセンスの下で提供されています。
引用
もしこのモデルが役に立った場合は、以下のように引用を考慮してください。
@misc{MonoQwen,
title={MonoQwen: Visual Document Reranking},
author={Chaffin, Antoine and Lac, Aurélien},
url={https://huggingface.co/lightonai/MonoQwen2-VL-v0.1},
year={2024}
}