revert README.md
Browse files
README.md
CHANGED
|
@@ -3692,11 +3692,16 @@ The `GME` models support three types of input: **text**, **image**, and **image-
|
|
| 3692 |
|[`gme-Qwen2-VL-7B`](https://huggingface.co/Alibaba-NLP/gme-Qwen2-VL-7B-Instruct) | 8.29B | 32768 | 3584 | 67.48 | 69.73 | 67.44 |
|
| 3693 |
|
| 3694 |
## Usage
|
|
|
|
| 3695 |
|
|
|
|
| 3696 |
|
| 3697 |
-
**
|
| 3698 |
|
| 3699 |
```python
|
|
|
|
|
|
|
|
|
|
| 3700 |
t2i_prompt = 'Find an image that matches the given text.'
|
| 3701 |
texts = [
|
| 3702 |
"The Tesla Cybertruck is a battery electric pickup truck built by Tesla, Inc. since 2023.",
|
|
@@ -3708,41 +3713,33 @@ images = [
|
|
| 3708 |
]
|
| 3709 |
|
| 3710 |
|
| 3711 |
-
|
| 3712 |
-
model_path,
|
| 3713 |
-
torch_dtype="float16", device_map='cuda', trust_remote_code=True
|
| 3714 |
-
)
|
| 3715 |
-
|
| 3716 |
|
| 3717 |
# Single-modal embedding
|
| 3718 |
-
e_text =
|
| 3719 |
-
e_image =
|
| 3720 |
print('Single-modal', (e_text @ e_image.T).tolist())
|
| 3721 |
-
## Single-modal [[0.
|
| 3722 |
|
| 3723 |
# How to set embedding instruction
|
| 3724 |
-
e_query =
|
| 3725 |
-
# If
|
| 3726 |
-
e_corpus =
|
| 3727 |
print('Single-modal with instruction', (e_query @ e_corpus.T).tolist())
|
| 3728 |
-
## Single-modal with instruction [[0.
|
| 3729 |
|
| 3730 |
# Fused-modal embedding
|
| 3731 |
-
e_fused =
|
| 3732 |
print('Fused-modal', (e_fused @ e_fused.T).tolist())
|
| 3733 |
-
## Fused-modal [[
|
| 3734 |
```
|
| 3735 |
|
| 3736 |
|
| 3737 |
-
**
|
| 3738 |
-
|
| 3739 |
-
The `encode` function accept `str` or `dict` with key(s) in `{'text', 'image', 'prompt'}`.
|
| 3740 |
-
|
| 3741 |
-
**Do not pass `prompt` as the argument to `encode`**, pass as the input as a `dict` with a `prompt` key.
|
| 3742 |
|
| 3743 |
```python
|
| 3744 |
-
|
| 3745 |
-
|
| 3746 |
|
| 3747 |
t2i_prompt = 'Find an image that matches the given text.'
|
| 3748 |
texts = [
|
|
@@ -3755,29 +3752,27 @@ images = [
|
|
| 3755 |
]
|
| 3756 |
|
| 3757 |
|
| 3758 |
-
|
| 3759 |
|
| 3760 |
# Single-modal embedding
|
| 3761 |
-
e_text =
|
| 3762 |
-
e_image =
|
| 3763 |
print('Single-modal', (e_text @ e_image.T).tolist())
|
| 3764 |
-
##
|
| 3765 |
|
| 3766 |
# How to set embedding instruction
|
| 3767 |
-
e_query =
|
| 3768 |
-
# If
|
| 3769 |
-
e_corpus =
|
| 3770 |
print('Single-modal with instruction', (e_query @ e_corpus.T).tolist())
|
| 3771 |
-
##
|
| 3772 |
|
| 3773 |
# Fused-modal embedding
|
| 3774 |
-
e_fused =
|
| 3775 |
print('Fused-modal', (e_fused @ e_fused.T).tolist())
|
| 3776 |
-
##
|
| 3777 |
```
|
| 3778 |
|
| 3779 |
-
|
| 3780 |
-
|
| 3781 |
## Evaluation
|
| 3782 |
|
| 3783 |
We validated the performance on our universal multimodal retrieval benchmark (**UMRB**, see [Release UMRB](https://huggingface.co/Alibaba-NLP/gme-Qwen2-VL-7B-Instruct/discussions/2)) among others.
|
|
|
|
| 3692 |
|[`gme-Qwen2-VL-7B`](https://huggingface.co/Alibaba-NLP/gme-Qwen2-VL-7B-Instruct) | 8.29B | 32768 | 3584 | 67.48 | 69.73 | 67.44 |
|
| 3693 |
|
| 3694 |
## Usage
|
| 3695 |
+
**Use with sentence_transformers**
|
| 3696 |
|
| 3697 |
+
The `encode` function accept `str` or `dict` with key(s) in `{'text', 'image', 'prompt'}`.
|
| 3698 |
|
| 3699 |
+
**Do not pass `prompt` as the argument to `encode`**, pass as the input as a `dict` with a `prompt` key.
|
| 3700 |
|
| 3701 |
```python
|
| 3702 |
+
from sentence_transformers import SentenceTransformer
|
| 3703 |
+
|
| 3704 |
+
|
| 3705 |
t2i_prompt = 'Find an image that matches the given text.'
|
| 3706 |
texts = [
|
| 3707 |
"The Tesla Cybertruck is a battery electric pickup truck built by Tesla, Inc. since 2023.",
|
|
|
|
| 3713 |
]
|
| 3714 |
|
| 3715 |
|
| 3716 |
+
gme_st = SentenceTransformer("Alibaba-NLP/gme-Qwen2-VL-2B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3717 |
|
| 3718 |
# Single-modal embedding
|
| 3719 |
+
e_text = gme_st.encode(texts, convert_to_tensor=True)
|
| 3720 |
+
e_image = gme_st.encode([dict(image=i) for i in images], convert_to_tensor=True)
|
| 3721 |
print('Single-modal', (e_text @ e_image.T).tolist())
|
| 3722 |
+
## Single-modal [[0.356201171875, 0.06536865234375], [0.041717529296875, 0.37890625]]
|
| 3723 |
|
| 3724 |
# How to set embedding instruction
|
| 3725 |
+
e_query = gme_st.encode([dict(text=t, prompt=t2i_prompt) for t in texts], convert_to_tensor=True)
|
| 3726 |
+
# If no prompt, we always use the default instruction.
|
| 3727 |
+
e_corpus = gme_st.encode([dict(image=i) for i in images], convert_to_tensor=True)
|
| 3728 |
print('Single-modal with instruction', (e_query @ e_corpus.T).tolist())
|
| 3729 |
+
## Single-modal with instruction [[0.425537109375, 0.1158447265625], [0.049835205078125, 0.413818359375]]
|
| 3730 |
|
| 3731 |
# Fused-modal embedding
|
| 3732 |
+
e_fused = gme_st.encode([dict(text=t, image=i) for t, i in zip(texts, images)], convert_to_tensor=True)
|
| 3733 |
print('Fused-modal', (e_fused @ e_fused.T).tolist())
|
| 3734 |
+
## Fused-modal [[0.99951171875, 0.0556640625], [0.0556640625, 0.99951171875]]
|
| 3735 |
```
|
| 3736 |
|
| 3737 |
|
| 3738 |
+
**Use with custom code**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3739 |
|
| 3740 |
```python
|
| 3741 |
+
# You can find the script gme_inference.py in https://huggingface.co/Alibaba-NLP/gme-Qwen2-VL-2B-Instruct/blob/main/gme_inference.py
|
| 3742 |
+
from gme_inference import GmeQwen2VL
|
| 3743 |
|
| 3744 |
t2i_prompt = 'Find an image that matches the given text.'
|
| 3745 |
texts = [
|
|
|
|
| 3752 |
]
|
| 3753 |
|
| 3754 |
|
| 3755 |
+
gme = GmeQwen2VL("Alibaba-NLP/gme-Qwen2-VL-2B-Instruct")
|
| 3756 |
|
| 3757 |
# Single-modal embedding
|
| 3758 |
+
e_text = gme.get_text_embeddings(texts=texts)
|
| 3759 |
+
e_image = gme.get_image_embeddings(images=images)
|
| 3760 |
print('Single-modal', (e_text @ e_image.T).tolist())
|
| 3761 |
+
## [[0.359619140625, 0.0655517578125], [0.04180908203125, 0.374755859375]]
|
| 3762 |
|
| 3763 |
# How to set embedding instruction
|
| 3764 |
+
e_query = gme.get_text_embeddings(texts=texts, instruction=t2i_prompt)
|
| 3765 |
+
# If is_query=False, we always use the default instruction.
|
| 3766 |
+
e_corpus = gme.get_image_embeddings(images=images, is_query=False)
|
| 3767 |
print('Single-modal with instruction', (e_query @ e_corpus.T).tolist())
|
| 3768 |
+
## [[0.429931640625, 0.11505126953125], [0.049835205078125, 0.409423828125]]
|
| 3769 |
|
| 3770 |
# Fused-modal embedding
|
| 3771 |
+
e_fused = gme.get_fused_embeddings(texts=texts, images=images)
|
| 3772 |
print('Fused-modal', (e_fused @ e_fused.T).tolist())
|
| 3773 |
+
## [[1.0, 0.05511474609375], [0.05511474609375, 1.0]]
|
| 3774 |
```
|
| 3775 |
|
|
|
|
|
|
|
| 3776 |
## Evaluation
|
| 3777 |
|
| 3778 |
We validated the performance on our universal multimodal retrieval benchmark (**UMRB**, see [Release UMRB](https://huggingface.co/Alibaba-NLP/gme-Qwen2-VL-7B-Instruct/discussions/2)) among others.
|