Multi-Modal Inference Library
For Semantic Search Applications
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 (12 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.
1from PIL import Image
23text ='a small red panda in a zoo'4image = Image.open('red_panda.jpg')56image_data = model.preprocess_image(image)7text_data = model.preprocess_text(text)89image_embedding = model.encode_image(image_data)10text_embedding = model.encode_text(text_data)11joint_embedding = model.encode_multimodal(image=image_data, text=text_data)
There are two options to calculate semantic compatibility between an image and a text: Cosine Similarity and Matching Score.
Cosine Similarity
python
1import torch.nn.functional as F
23similarity = 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.