Multilingual-CLIP extends OpenAI's English text encoders to multiple other languages. This model only contains the multilingual text encoder. The corresponding image model ViT-B-32 can be retrieved via instructions found on OpenAI's CLIP repository on Github. We provide a usage example below.
Requirements
To use both the multilingual text encoder and corresponding image encoder, we need to install the packages multilingual-clip and clip.
Extracting embeddings from the text encoder can be done in the following way:
python
1from multilingual_clip import pt_multilingual_clip
2import transformers
34texts =[5'Three blind horses listening to Mozart.',6'Älgen är skogens konung!',7'Wie leben Eisbären in der Antarktis?',8'Вы знали, что все белые медведи левши?'9]10model_name ='M-CLIP/XLM-Roberta-Large-Vit-B-32'1112# Load Model & Tokenizer13model = pt_multilingual_clip.MultilingualCLIP.from_pretrained(model_name)14tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)1516embeddings = model.forward(texts, tokenizer)17print("Text features shape:", embeddings.shape)
Extracting embeddings from the corresponding image encoder:
None of the M-CLIP models have been extensivly evaluated, but testing them on Txt2Img retrieval on the humanly translated MS-COCO dataset, we see the following R@10 results: