Visual Document Retrieval
sentence-transformers
Safetensors
qwen2_5_omni_thinker
multimodal
feature-extraction
Instructions to use Haon-Chen/e5-omni-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Haon-Chen/e5-omni-3B with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Haon-Chen/e5-omni-3B") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- .gitattributes +6 -0
- README.md +132 -3
- assets/jay_chou_superman_cant_fly.mp3 +3 -0
- assets/joe_hisaishi_summer.mp3 +3 -0
- assets/llama4_hgf.png +3 -0
- assets/mapo_tofu.mp4 +3 -0
- assets/qwen2.5omni_hgf.png +3 -0
- assets/zhajiang_noodle.mp4 +3 -0
.gitattributes
CHANGED
|
@@ -34,3 +34,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/jay_chou_superman_cant_fly.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/joe_hisaishi_summer.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
assets/llama4_hgf.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
assets/mapo_tofu.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
assets/qwen2.5omni_hgf.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
assets/zhajiang_noodle.mp4 filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,3 +1,132 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model:
|
| 4 |
+
- Qwen/Qwen2.5-Omni-3B
|
| 5 |
+
pipeline_tag: visual-document-retrieval
|
| 6 |
+
library_name: peft
|
| 7 |
+
---
|
| 8 |
+
# Haon-Chen/e5-omni-3B
|
| 9 |
+
|
| 10 |
+
**e5-omni-3B** is a powerful omni-modal embedding model built on [Qwen2.5-Omni-3B](https://huggingface.co/Qwen/Qwen2.5-Omni-3B).
|
| 11 |
+
e5-omni-3B generates unified embeddings across text, images, audio, and video, enabling effective cross-modal retrieval for diverse applications. [Paper](https://arxiv.org/pdf/2505.02466v1).
|
| 12 |
+
|
| 13 |
+
📝 Text 🖼️ Image 🎧 Audio 🎥 Video 🌐 Multilingual
|
| 14 |
+
|
| 15 |
+
## Experimental Results
|
| 16 |
+
Our model achieves SOTA performance on MMEB benchmark.
|
| 17 |
+
<img width="900" alt="abs" src="https://raw.githubusercontent.com/haon-chen/mmE5/refs/heads/main/figures//exp_result.jpg">
|
| 18 |
+
|
| 19 |
+
## Usage
|
| 20 |
+
|
| 21 |
+
Below is an example we adapted from [Tevatron](https://huggingface.co/Tevatron/OmniEmbed-v0.1).
|
| 22 |
+
|
| 23 |
+
```python
|
| 24 |
+
# Import Library, Load Model and Processor
|
| 25 |
+
import torch
|
| 26 |
+
from transformers import AutoProcessor, Qwen2_5OmniThinkerForConditionalGeneration
|
| 27 |
+
from qwen_omni_utils import process_mm_info
|
| 28 |
+
|
| 29 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 30 |
+
|
| 31 |
+
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-Omni-3B")
|
| 32 |
+
model = Qwen2_5OmniThinkerForConditionalGeneration.from_pretrained(
|
| 33 |
+
"Haon-Chen/e5-omni-3B",
|
| 34 |
+
attn_implementation="flash_attention_2",
|
| 35 |
+
torch_dtype=torch.bfloat16
|
| 36 |
+
).to(device).eval()
|
| 37 |
+
|
| 38 |
+
processor.tokenizer.padding_side = "left"
|
| 39 |
+
model.padding_side = "left"
|
| 40 |
+
|
| 41 |
+
# Function to Encode Message
|
| 42 |
+
def encode_message(message):
|
| 43 |
+
texts = processor.apply_chat_template(message, tokenize=False, add_generation_prompt=True)[0] + "<|endoftext|>"
|
| 44 |
+
audio_inputs, image_inputs, video_inputs = process_mm_info(message, use_audio_in_video=True)
|
| 45 |
+
|
| 46 |
+
inputs = processor(
|
| 47 |
+
text=texts,
|
| 48 |
+
audio=audio_inputs,
|
| 49 |
+
images=image_inputs,
|
| 50 |
+
videos=video_inputs,
|
| 51 |
+
return_tensors="pt",
|
| 52 |
+
padding="longest",
|
| 53 |
+
)
|
| 54 |
+
for k in inputs:
|
| 55 |
+
inputs[k] = inputs[k].to(device)
|
| 56 |
+
|
| 57 |
+
cache_position = torch.arange(0, inputs["input_ids"].shape[1], device=device)
|
| 58 |
+
inputs = model.prepare_inputs_for_generation(**inputs, use_cache=True, cache_position=cache_position)
|
| 59 |
+
model_outputs = model(**inputs, return_dict=True, output_hidden_states=True)
|
| 60 |
+
|
| 61 |
+
last_hidden_state = model_outputs.hidden_states[-1]
|
| 62 |
+
reps = last_hidden_state[:, -1]
|
| 63 |
+
reps = torch.nn.functional.normalize(reps, p=2, dim=-1)
|
| 64 |
+
return reps
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### 🎬 Video Retrieval
|
| 68 |
+
```python
|
| 69 |
+
example_query = "Query: How to cook Mapo Tofu?"
|
| 70 |
+
example_video_1 = "https://huggingface.co/Tevatron/OmniEmbed-v0.1/resolve/main/assets/mapo_tofu.mp4"
|
| 71 |
+
example_video_2 = "https://huggingface.co/Tevatron/OmniEmbed-v0.1/resolve/main/assets/zhajiang_noodle.mp4"
|
| 72 |
+
query = [{"role": "user", "content": [{"type": "text", "text": example_query}]}]
|
| 73 |
+
video_1 = [{"role": "user", "content": [{"type": "video", "video": example_video_1}]}]
|
| 74 |
+
video_2 = [{"role": "user", "content": [{"type": "video", "video": example_video_2}]}]
|
| 75 |
+
|
| 76 |
+
sim1 = torch.cosine_similarity(encode_message(query), encode_message(video_1))
|
| 77 |
+
sim2 = torch.cosine_similarity(encode_message(query), encode_message(video_2))
|
| 78 |
+
|
| 79 |
+
print("Similarities:", sim1.item(), sim2.item())
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### 🎵 Audio Retrieval
|
| 83 |
+
```python
|
| 84 |
+
example_query = "Query: A light piano piece"
|
| 85 |
+
example_audio_1 = "https://huggingface.co/Tevatron/OmniEmbed-v0.1/resolve/main/assets/joe_hisaishi_summer.mp3"
|
| 86 |
+
example_audio_2 = "https://huggingface.co/Tevatron/OmniEmbed-v0.1/resolve/main/assets/jay_chou_superman_cant_fly.mp3"
|
| 87 |
+
query = [{"role": "user", "content": [{"type": "text", "text": example_query}]}]
|
| 88 |
+
audio_1 = [{"role": "user", "content": [{"type": "audio", "audio": example_audio_1}]}]
|
| 89 |
+
audio_2 = [{"role": "user", "content": [{"type": "audio", "audio": example_audio_2}]}]
|
| 90 |
+
|
| 91 |
+
sim1 = torch.cosine_similarity(encode_message(query), encode_message(audio_1))
|
| 92 |
+
sim2 = torch.cosine_similarity(encode_message(query), encode_message(audio_2))
|
| 93 |
+
|
| 94 |
+
print("Similarities:", sim1.item(), sim2.item())
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### 📈 Image Document Retrieval (Image, Chart, PDF)
|
| 98 |
+
```python
|
| 99 |
+
example_query = "Query: How many input modality does Qwen2.5-Omni support?"
|
| 100 |
+
example_image_1 = "https://huggingface.co/Tevatron/OmniEmbed-v0.1/resolve/main/assets/qwen2.5omni_hgf.png"
|
| 101 |
+
example_image_2 = "https://huggingface.co/Tevatron/OmniEmbed-v0.1/resolve/main/assets/llama4_hgf.png"
|
| 102 |
+
query = [{"role": "user", "content": [{"type": "text", "text": example_query}]}]
|
| 103 |
+
image_1 = [{"role": "user", "content": [{"type": "image", "image": example_image_1}]}]
|
| 104 |
+
image_2 = [{"role": "user", "content": [{"type": "image", "image": example_image_2}]}]
|
| 105 |
+
|
| 106 |
+
sim1 = torch.cosine_similarity(encode_message(query), encode_message(image_1))
|
| 107 |
+
sim2 = torch.cosine_similarity(encode_message(query), encode_message(image_2))
|
| 108 |
+
|
| 109 |
+
print("Similarities:", sim1.item(), sim2.item())
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
### 🌍 Multilingual Text Retrieval
|
| 113 |
+
```python
|
| 114 |
+
example_query = "Query: 氧气在空气中占比多少?"
|
| 115 |
+
example_text_1 = "空气是指大气层中由不同气体和各类飘浮在其��的固体与液体颗粒(大气颗粒与气溶胶)所组成的气态混合物。地球大气层的空气主要由78.1%的氮气、20.9%氧气、0.9%的氩气和1~4%的水蒸气组成,其成分并不是固定的,随着高度、气压、温度的改变和对流情况不同,局部空气的组成比例也会改变。空气在大气层(特别是对流层)中的流动形成了风和曳流、气旋、龙卷等自然现象,而空气中飘浮的颗粒则形成了云、雾、霾和沙尘暴等短期天气情况。空气在海洋和陆地之间跨区域流动所承载的湿度和热能传导也是水循环和气候变率与变化的关键一环。"
|
| 116 |
+
example_text_2 = "水(化学式:H2O)是一种无机化合物,在常温且无杂质中是无色[1]无味不导电的透明液体,也会通过蒸发产生气态的水蒸气(这种蒸发可以发生在任何温度下,同时取决于与空气接触的表面积和湿度差)。在标准大气压下,水的凝固点是0 °C(32 °F;273 K),沸点是100 °C(212 °F;373 K)。"
|
| 117 |
+
query = [{"role": "user", "content": [{"type": "text", "text": example_query}]}]
|
| 118 |
+
text_1 = [{"role": "user", "content": [{"type": "text", "text": example_text_1}]}]
|
| 119 |
+
text_2 = [{"role": "user", "content": [{"type": "text", "text": example_text_2}]}]
|
| 120 |
+
|
| 121 |
+
sim1 = torch.cosine_similarity(encode_message(query), encode_message(text_1))
|
| 122 |
+
sim2 = torch.cosine_similarity(encode_message(query), encode_message(text_2))
|
| 123 |
+
|
| 124 |
+
print("Similarities:", sim1.item(), sim2.item())
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
## Citation
|
| 128 |
+
```
|
| 129 |
+
@article{
|
| 130 |
+
}
|
| 131 |
+
```
|
| 132 |
+
|
assets/jay_chou_superman_cant_fly.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f54d08b9eecf4003b692daaff28f5387804a93a27deb1d5ce663e764a27de1d3
|
| 3 |
+
size 4872832
|
assets/joe_hisaishi_summer.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:979c14285b90422965ecbce68c88b69dcb1e9328d78b5329c6a965eda0cfb938
|
| 3 |
+
size 2638661
|
assets/llama4_hgf.png
ADDED
|
Git LFS Details
|
assets/mapo_tofu.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:23bd7a2a9a554bc09084cb74e584ca6129292073efcd2350f180e81975f96ec5
|
| 3 |
+
size 5250889
|
assets/qwen2.5omni_hgf.png
ADDED
|
Git LFS Details
|
assets/zhajiang_noodle.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:640b98fde893982dc0e866e72d537d9798a5a8432a6a7abc8f76d630c897a1b1
|
| 3 |
+
size 3571831
|