M-CLIP/LABSE-Vit-L-14

Model

3

stars

3

commits

9

repos using this model

2

linked in READMEs

Jun 2, 2022

updated

endpoints_compatible
multilingual
pytorch
tf
transformers

README

Multilingual-clip: LABSE-Vit-L-14

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-L-14 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.

pip install multilingual-clip
pip install git+https://github.com/openai/CLIP.git

Usage

Extracting embeddings from the text encoder can be done in the following way:

from multilingual_clip import pt_multilingual_clip
import transformers

texts = [
    'Three blind horses listening to Mozart.',
    'Älgen är skogens konung!',
    'Wie leben Eisbären in der Antarktis?',
    'Вы знали, что все белые медведи левши?'
]
model_name = 'M-CLIP/LABSE-Vit-L-14'

# Load Model & Tokenizer
model = pt_multilingual_clip.MultilingualCLIP.from_pretrained(model_name)
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)

embeddings = model.forward(texts, tokenizer)
print("Text features shape:", embeddings.shape)

Extracting embeddings from the corresponding image encoder:

import torch
import clip
import requests
from PIL import Image

device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-L/14", device=device)

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
image = preprocess(image).unsqueeze(0).to(device)

with torch.no_grad():
    image_features = model.encode_image(image)

print("Image features shape:", image_features.shape) 

Evaluation results

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:

NameEnDeEsFrZhItPlKoRuTrJp
OpenAI CLIP Vit-B/3290.3----------
OpenAI CLIP Vit-L/1491.8----------
OpenCLIP ViT-B-16+-94.3----------
LABSE Vit-L/1491.689.689.589.988.990.189.880.885.589.873.9
XLM-R Large Vit-B/3291.888.789.189.489.389.891.482.186.188.881.0
XLM-R Vit-L/1492.490.691.090.089.791.191.385.285.890.381.9
XLM-R Large Vit-B/16+95.093.093.693.194.093.194.489.090.093.084.2

Training/Model details

Further details about the model training and data can be found in the model card.

Contributors

FreddeFrallan

1 commits

FC
Lauler

1 commits

M-CLIP/LABSE-Vit-L-14

Model

3

stars

3

commits

9

repos using this model

2

linked in READMEs

Jun 2, 2022

updated

endpoints_compatible
multilingual
pytorch
tf
transformers

README

Multilingual-clip: LABSE-Vit-L-14

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-L-14 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.

pip install multilingual-clip
pip install git+https://github.com/openai/CLIP.git

Usage

Extracting embeddings from the text encoder can be done in the following way:

from multilingual_clip import pt_multilingual_clip
import transformers

texts = [
    'Three blind horses listening to Mozart.',
    'Älgen är skogens konung!',
    'Wie leben Eisbären in der Antarktis?',
    'Вы знали, что все белые медведи левши?'
]
model_name = 'M-CLIP/LABSE-Vit-L-14'

# Load Model & Tokenizer
model = pt_multilingual_clip.MultilingualCLIP.from_pretrained(model_name)
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)

embeddings = model.forward(texts, tokenizer)
print("Text features shape:", embeddings.shape)

Extracting embeddings from the corresponding image encoder:

import torch
import clip
import requests
from PIL import Image

device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-L/14", device=device)

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
image = preprocess(image).unsqueeze(0).to(device)

with torch.no_grad():
    image_features = model.encode_image(image)

print("Image features shape:", image_features.shape) 

Evaluation results

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:

NameEnDeEsFrZhItPlKoRuTrJp
OpenAI CLIP Vit-B/3290.3----------
OpenAI CLIP Vit-L/1491.8----------
OpenCLIP ViT-B-16+-94.3----------
LABSE Vit-L/1491.689.689.589.988.990.189.880.885.589.873.9
XLM-R Large Vit-B/3291.888.789.189.489.389.891.482.186.188.881.0
XLM-R Vit-L/1492.490.691.090.089.791.191.385.285.890.381.9
XLM-R Large Vit-B/16+95.093.093.693.194.093.194.489.090.093.084.2

Training/Model details

Further details about the model training and data can be found in the model card.

Contributors

FreddeFrallan

1 commits

FC
Lauler

1 commits