Views
No views yet
2024-3-4 🚀🚀 We have released the BGE-VL-MLLM models on Huggingface: BGE-VL-MLLM-S1 and BGE-VL-MLLM-S2. BGE-VL-MLLM-S1 is trained exclusively on our MegaPairs dataset, achieving outstanding performance in composed image retrieval, with an 8.1% improvement on the CIRCO benchmark (mAP@5) over the previous state-of-the-art. BGE-VL-MLLM-S2 builds on BGE-VL-MLLM-S1 with an additional epoch of fine-tuning on the MMEB benchmark training set, delivering enhanced performance across a broader range of multimodal embedding tasks.2024-12-19 🎉🎉 Release our paper: MegaPairs: Massive Data Synthesis For Universal Multimodal Retrieval.pip install sentence_transformers[image]1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("BAAI/BGE-VL-large", trust_remote_code=True)
4
5query_image = "https://huggingface.co/BAAI/BGE-VL-large/resolve/main/assets/cir_query.png"
6candidate_1 = "https://huggingface.co/BAAI/BGE-VL-large/resolve/main/assets/cir_candi_1.png"
7candidate_2 = "https://huggingface.co/BAAI/BGE-VL-large/resolve/main/assets/cir_candi_2.png"
8
9# Encode text
10text_embeddings = model.encode(["A dog sitting on a bench", "A cat sleeping on a couch"])
11print(text_embeddings.shape)
12# (2, 768)
13
14# Encode images
15image_embeddings = model.encode([query_image, candidate_1])
16print(image_embeddings.shape)
17# (2, 768)
18
19# Compute similarities
20similarities = model.similarity(text_embeddings, image_embeddings)
21print(similarities)
22# tensor([[0.1255, 0.1018],
23# [0.0161, 0.0271]])
24
25# Composed image retrieval: encode image+text query, compare with image candidates
26query_embeddings = model.encode([{
27 "image": query_image,
28 "text": "Make the background dark, as if the camera has taken the photo at night",
29}])
30candidate_embeddings = model.encode([candidate_1, candidate_2])
31scores = model.similarity(query_embeddings, candidate_embeddings)
32print(scores)
33# tensor([[0.3696, 0.1714]])encode function. The model will automatically process the inputs and return the corresponding embeddings. You can then compute cosine similarities or perform retrieval tasks based on these embeddings.transformers1import torch
2from transformers import AutoModel
3
4MODEL_NAME = "BAAI/BGE-VL-base" # or "BAAI/BGE-VL-large"
5
6model = AutoModel.from_pretrained(MODEL_NAME, trust_remote_code=True) # You must set trust_remote_code=True
7model.set_processor(MODEL_NAME)
8model.eval()
9
10with torch.no_grad():
11 query = model.encode(
12 images = "./assets/cir_query.png",
13 text = "Make the background dark, as if the camera has taken the photo at night"
14 )
15
16 candidates = model.encode(
17 images = ["./assets/cir_candi_1.png", "./assets/cir_candi_2.png"]
18 )
19
20 scores = query @ candidates.T
21print(scores)1import torch
2from transformers import AutoModel
3from PIL import Image
4
5MODEL_NAME= "BAAI/BGE-VL-MLLM-S1"
6
7model = AutoModel.from_pretrained(MODEL_NAME, trust_remote_code=True)
8model.eval()
9model.cuda()
10
11with torch.no_grad():
12 model.set_processor(MODEL_NAME)
13
14 query_inputs = model.data_process(
15 text="Make the background dark, as if the camera has taken the photo at night",
16 images="./assets/cir_query.png",
17 q_or_c="q",
18 task_instruction="Retrieve the target image that best meets the combined criteria by using both the provided image and the image retrieval instructions: "
19 )
20
21 candidate_inputs = model.data_process(
22 images=["./assets/cir_candi_1.png", "./assets/cir_candi_2.png"],
23 q_or_c="c",
24 )
25
26 query_embs = model(**query_inputs, output_hidden_states=True)[:, -1, :]
27 candi_embs = model(**candidate_inputs, output_hidden_states=True)[:, -1, :]
28
29 query_embs = torch.nn.functional.normalize(query_embs, dim=-1)
30 candi_embs = torch.nn.functional.normalize(candi_embs, dim=-1)
31
32 scores = torch.matmul(query_embs, candi_embs.T)
33print(scores)



@article{zhou2024megapairs,
title={MegaPairs: Massive Data Synthesis For Universal Multimodal Retrieval},
author={Zhou, Junjie and Liu, Zheng and Liu, Ze and Xiao, Shitao and Wang, Yueze and Zhao, Bo and Zhang, Chen Jason and Lian, Defu and Xiong, Yongping},
journal={arXiv preprint arXiv:2412.14475},
year={2024}
}