Lauler commited on
Commit
e421c71
1 Parent(s): dc925ee

Add README

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Model card: multilingual-clip
2
+
3
+ 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` needs to be retrieved via instructions found on from OpenAI's [CLIP repository on Github](https://github.com/openai/CLIP). We provide a usage example below.
4
+
5
+ ## Requirements
6
+
7
+ To use both the multilingual text encoder and corresponding image encoder, we need to install the packages `multilingual-clip` and `clip`.
8
+
9
+ ```
10
+ pip install multilingual-clip
11
+ pip install git+https://github.com/openai/CLIP.git
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Extracting embeddings from the text encoder can be done in the following way:
17
+
18
+ ```python
19
+ from multilingual_clip import pt_multilingual_clip
20
+ import transformers
21
+
22
+ texts = [
23
+ 'Three blind horses listening to Mozart.',
24
+ 'Älgen är skogens konung!',
25
+ 'Wie leben Eisbären in der Antarktis?',
26
+ 'Вы знали, что все белые медведи левши?'
27
+ ]
28
+ model_name = 'M-CLIP/XLM-Roberta-Large-Vit-B-32'
29
+
30
+ # Load Model & Tokenizer
31
+ model = pt_multilingual_clip.MultilingualCLIP.from_pretrained(model_name)
32
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
33
+
34
+ embeddings = model.forward(texts, tokenizer)
35
+ print("Text features shape:", embeddings.shape)
36
+ ```
37
+
38
+ Extracting embeddings from the corresponding image encoder:
39
+
40
+ ```python
41
+ import torch
42
+ import clip
43
+ import requests
44
+ from PIL import Image
45
+
46
+ device = "cuda" if torch.cuda.is_available() else "cpu"
47
+ model, preprocess = clip.load("ViT-B/32", device=device)
48
+
49
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
50
+ image = Image.open(requests.get(url, stream=True).raw)
51
+ image = preprocess(image).unsqueeze(0).to(device)
52
+
53
+ with torch.no_grad():
54
+ image_features = model.encode_image(image)
55
+
56
+ print("Image features shape:", image_features.shape)
57
+ ```
58
+
59
+ ## Evaluation results
60
+
61
+ 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:
62
+ | Name | En | De | Es | Fr | Zh | It | Pl | Ko | Ru | Tr | Jp |
63
+ | ----------------------------------|:-----: |:-----: |:-----: |:-----: | :-----: |:-----: |:-----: |:-----: |:-----: |:-----: |:-----: |
64
+ | [OpenAI CLIP Vit-B/32](https://github.com/openai/CLIP)| 90.3 | - | - | - | - | - | - | - | - | - | - |
65
+ | [OpenAI CLIP Vit-L/14](https://github.com/openai/CLIP)| 91.8 | - | - | - | - | - | - | - | - | - | - |
66
+ | [LABSE Vit-L/14](https://huggingface.co/M-CLIP/LABSE-Vit-L-14)| 91.6 | 89.6 | 89.5 | 89.9 | 88.9 | 90.1 | 89.8 | 80.8 | 85.5 | 89.8 | 73.9 |
67
+ | [XLM-R Large Vit-B/32](https://huggingface.co/M-CLIP/XLM-Roberta-Large-Vit-B-32)| 91.8 | 88.7 | 89.1 | 89.4 | 89.3 | 89.8| 91.4 | 82.1 | 86.1 | 88.8 | 81.0 |
68
+ | [XLM-R Vit-L/14](https://huggingface.co/M-CLIP/XLM-Roberta-Large-Vit-L-14)| 92.4 | 90.6 | 91.0 | 90.0 | 89.7 | 91.1 | 91.3 | 85.2 | 85.8 | 90.3 | 81.9 |
69
+ | [XLM-R Large Vit-B/16+](https://huggingface.co/M-CLIP/XLM-Roberta-Large-Vit-B-16Plus)| <b>95.0</b> | <b>93.0</b> | <b>93.6</b> | <b>93.1</b> | <b>94.0</b> | <b>93.1</b> | <b>94.4</b> | <b>89.0</b> | <b>90.0</b> | <b>93.0</b> | <b>84.2</b> |
70
+
71
+
72
+ ## Training/Model details
73
+
74
+ Details about the model training and data can be found in the [model card](https://github.com/FreddeFrallan/Multilingual-CLIP/blob/main/larger_mclip.md).