Our model is being trained on MMEB-train and evaluated on MMEB-eval with contrastive learning. We only use in-batch negatives for training. Our best results were based on Lora training with batch size of 1024. We also have checkpoint with full training with batch size of 2048. Our results on 36 evaluation datasets are:
Then you can enter the directory to run the following command.
python
1from src.model import MMEBModel
2from src.arguments import ModelArguments
3from src.utils import load_processor
4import torch
5from transformers import HfArgumentParser, AutoProcessor
6from PIL import Image
7import numpy as np
89model_args = ModelArguments(10 model_name='TIGER-Lab/VLM2Vec-Full',11 pooling='last',12 normalize=True,13 model_backbone='phi3_v',14 num_crops=16)1516processor = load_processor(model_args)1718model = MMEBModel.load(model_args)19model.eval()20model = model.to('cuda', dtype=torch.bfloat16)212223# Image + Text -> Text24inputs = processor('<|image_1|> Represent the given image with the following question: What is in the image',[Image.open(25'figures/example.jpg')])26inputs ={key: value.to('cuda')for key, value in inputs.items()}27qry_output = model(qry=inputs)["qry_reps"]2829string ='A cat and a dog'30inputs = processor(string)31inputs ={key: value.to('cuda')for key, value in inputs.items()}32tgt_output = model(tgt=inputs)["tgt_reps"]33print(string,'=', model.compute_similarity(qry_output, tgt_output))34## A cat and a dog = tensor([[0.3008]], device='cuda:0', dtype=torch.bfloat16)3536string ='A cat and a tiger'37inputs = processor(string)38inputs ={key: value.to('cuda')for key, value in inputs.items()}39tgt_output = model(tgt=inputs)["tgt_reps"]40print(string,'=', model.compute_similarity(qry_output, tgt_output))41## A cat and a tiger = tensor([[0.2051]], device='cuda:0', dtype=torch.bfloat16)4243# Text -> Image44inputs = processor('Find me an everyday image that matches the given caption: A cat and a dog.',)45inputs ={key: value.to('cuda')for key, value in inputs.items()}46qry_output = model(qry=inputs)["qry_reps"]4748string ='<|image_1|> Represent the given image.'49inputs = processor(string,[Image.open('figures/example.jpg')])50inputs ={key: value.to('cuda')for key, value in inputs.items()}51tgt_output = model(tgt=inputs)["tgt_reps"]52print(string,'=', model.compute_similarity(qry_output, tgt_output))53## <|image_1|> Represent the given image. = tensor([[0.2930]], device='cuda:0', dtype=torch.bfloat16)5455inputs = processor('Find me an everyday image that matches the given caption: A cat and a tiger.',)56inputs ={key: value.to('cuda')for key, value in inputs.items()}57qry_output = model(qry=inputs)["qry_reps"]5859string ='<|image_1|> Represent the given image.'60inputs = processor(string,[Image.open('figures/example.jpg')])61inputs ={key: value.to('cuda')for key, value in inputs.items()}62tgt_output = model(tgt=inputs)["tgt_reps"]63print(string,'=', model.compute_similarity(qry_output, tgt_output))64## <|image_1|> Represent the given image. = tensor([[0.2012]], device='cuda:0', dtype=torch.bfloat16)
Citation
@article{jiang2024vlm2vec,
title={VLM2Vec: Training Vision-Language Models for Massive Multimodal Embedding Tasks},
author={Jiang, Ziyan and Meng, Rui and Yang, Xinyi and Yavuz, Semih and Zhou, Yingbo and Chen, Wenhu},
journal={arXiv preprint arXiv:2410.05160},
year={2024}
}