CoolFace
Modelpublic

unum-cloud/uform-vl-multilingual-v2

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
27likes
Model Card

<h1 align="center">UForm</h1> <h3 align="center"> Multi-Modal Inference Library<br/> For Semantic Search Applications<br/> </h3>


UForm is a Multi-Modal Modal Inference package, designed to encode Multi-Lingual Texts, Images, and, soon, Audio, Video, and Documents, into a shared vector space!

This is model card of the _Multilingual model_ (21 languages) with:

  • 12 layers BERT (8 layers for unimodal encoding and rest layers for multimodal encoding)
  • ViT-B/16 (image resolution is 224x224)

The model was trained on balanced multilingual dataset.

If you need English model, check this.

Evaluation

For all evaluations, the multimodal part was used unless otherwise stated.

Monolingual

DatasetRecall@1Recall@5Recall@10
Zero-Shot Flickr0.5580.8130.874
MS-COCO (train split was in training data)0.4010.6800.781

Multilingual

XTD-10

Metric is recall@10

EnglishGermanSpanishFrenchItalianRussianJapaneseKoreanTurkishChinesePolish
96.193.595.794.194.490.490.291.395.293.895.8

COCO-SM

For this evaluation only unimodal part was used.

Recall

Target LanguageOpenCLIP @ 1UForm @ 1OpenCLIP @ 5UForm @ 5OpenCLIP @ 10UForm @ 10Speakers
Arabic22.731.744.957.855.869.2274 M
Armenian5.622.014.344.720.256.04 M
Chinese27.332.251.359.062.170.51'118 M
English37.837.763.565.073.575.91'452 M
French31.335.456.562.667.473.3274 M
German31.735.156.962.267.473.3134 M
Hebrew23.726.746.351.857.063.59 M
Hindi20.731.342.557.953.769.6602 M
Indonesian26.930.751.457.062.768.6199 M
Italian31.334.956.762.167.173.167 M
Japanese27.432.651.559.262.670.6125 M
Korean24.431.548.157.859.269.281 M
Persian24.028.847.054.657.866.277 M
Polish29.233.653.960.164.771.341 M
Portuguese31.632.757.159.667.971.0257 M
Russian29.933.954.860.965.872.0258 M
Spanish32.635.658.062.868.873.7548 M
Thai21.528.743.054.653.766.061 M
Turkish25.533.049.159.660.370.888 M
Ukranian26.030.649.956.760.968.141 M
Vietnamese25.428.349.253.960.365.585 M
Mean26.5±6.431.8±3.549.8±9.858.1±4.560.4±10.669.4±4.3-
Google Translate27.4±6.331.5±3.551.1±9.557.8±4.461.7±10.369.1±4.3-
Microsoft Translator27.2±6.431.4±3.650.8±9.857.7±4.761.4±10.668.9±4.6-
Meta NLLB24.9±6.732.4±3.547.5±10.358.9±4.558.2±11.270.2±4.3-

NDCG@20

ArabicArmenianChineseFrenchGermanHebrewHindiIndonesianItalianJapaneseKoreanPersianPolishPortugueseRussianSpanishThaiTurkishUkranianVietnameseMean (all)Mean (Google Translate)Mean(Microsoft Translator)Mean(NLLB)
OpenCLIP NDCG0.6390.2040.7310.8230.8060.6570.6160.7330.8110.7370.6860.6670.7640.8320.7770.8490.6060.7010.7040.6970.716 ± 0.1490.732 ± 0.1450.730 ± 0.1490.686 ± 0.158
UForm NDCG0.8680.6910.8800.9320.9270.7910.8790.8700.9300.8850.8690.8310.8970.8970.9060.9390.8220.8980.8510.8180.875 ± 0.0640.869 ± 0.0630.869 ± 0.0660.888 ± 0.064

Installation

bash
pip install uform[torch]

Usage

To load the model:

python
import uform

model, processor = uform.get_model('unum-cloud/uform-vl-multilingual-v2')

To encode data:

python
from PIL import Image

text = 'a small red panda in a zoo'
image = Image.open('red_panda.jpg')

image_data = processor.preprocess_image(image)
text_data = processor.preprocess_text(text)

image_features, image_embedding = model.encode_image(image_data, return_features=True)
text_features, text_embedding = model.encode_text(text_data, return_features=True)
joint_embedding = model.encode_multimodal(image=image_data, text=text_data)

To get features:

python
image_features, image_embedding = model.encode_image(image_data, return_features=True)
text_features, text_embedding = model.encode_text(text_data, return_features=True)

These features can later be used to produce joint multimodal encodings faster, as the first layers of the transformer can be skipped:

python
joint_embedding = model.encode_multimodal(
    image_features=image_features,
    text_features=text_features,
    attention_mask=text_data['attention_mask']
)

There are two options to calculate semantic compatibility between an image and a text: Cosine Similarity and Matching Score.

Cosine Similarity

python
import torch.nn.functional as F

similarity = F.cosine_similarity(image_embedding, text_embedding)

The similarity will belong to the [-1, 1] range, 1 meaning the absolute match.

_Pros_:

  • Computationally cheap.
  • Only unimodal embeddings are required, unimodal encoding is faster than joint encoding.
  • Suitable for retrieval in large collections.

_Cons_:

  • Takes into account only coarse-grained features.

Matching Score

Unlike cosine similarity, unimodal embedding are not enough. Joint embedding will be needed and the resulting score will belong to the [0, 1] range, 1 meaning the absolute match.

python
score = model.get_matching_scores(joint_embedding)

_Pros_:

  • Joint embedding captures fine-grained features.
  • Suitable for re-ranking – sorting retrieval result.

_Cons_:

  • Resource-intensive.
  • Not suitable for retrieval in large collections.