# UForm v2: now in 21 languages

> Releasing UForm v2 with support for 21 languages, delivering state-of-the-art efficiency in AI-based text-to-image search and multimodal embeddings.

[Blog](https://www.unum.cloud/blog.md) [AI](https://www.unum.cloud/blog?tag=AI)

Releasing UForm v2 with support for 21 languages, delivering state-of-the-art efficiency in AI-based text-to-image search and multimodal embeddings.

- By

  Ash Vardanian

- Published

  Aug 17, 2023

A few months ago, we [launched the inaugural version of UForm](https://www.unum.cloud/blog/efficient-multimodality.md), the efficient Vision-Language Transformer AI model designed for search applications. It was uniquely trained on a **balanced** multi-lingual dataset spanning 12 languages to empower a wider range of applications all across the globe. Since then, we’ve innovated with new techniques to cram even more learning capacity into our compact, cost-effective retrieval-oriented models. Here’s what UForm v2 brings to the table:

- 🌍 **Global Reach:** UForm v2 speaks Armenian 🇦🇲 and 20 popular languages: English 🇺🇸, German 🇩🇪, French 🇫🇷, Spanish 🇪🇸, Portuguese 🇵🇹, Italian 🇮🇹, Polish 🇵🇱, Ukrainian 🇺🇦, Russian 🇷🇺, Turkish 🇹🇷, Persian 🇮🇷, Hebrew 🇮🇱, Chinese 🇨🇳, Vietnamese 🇻🇳, Thai 🇹🇭, Indonesian 🇮🇩, Korean 🇰🇷, Japanese 🇯🇵, with some of the biggest gains in Arabic 🇸🇦 and Hindi 🇮🇳.
- 🚀 **Peak Performance:** While the default OpenCLIP achieves a 73.5% recall (at 10) for English text-to-image search, UForm v2 hits 75.9% in English and exceeds 70% in 10 other languages.
- ⚡ **Streamlined Efficiency:** Our model crafts embeddings that are half the size (256 dimensions vs. 512), doubling the speed of searches and recommendations. This boost is especially noticeable when paired with our [USearch vector-search engine](https://github.com/unum-cloud/USearch).
- 💵 **Cost-Effective:** UForm is open-source and optimized for cheaper and faster inference. In partnership with [Graphcore](https://graphcore.ai/), we’ve fine-tuned UForm for model-parallelism, achieving 6x larger batch sizes and unparalleled throughput compared to conventional CLIP models.

[![Animation showcasing search bar input in different languages](https://www.unum.cloud/blog/uform-graphcore/usearch-images-slow.gif)](http://usearch-images.com/)

What’s a release without a demo to showcase it? We’ve melded StreamLit, [USearch](https://github.com/unum-cloud/USearch), and the latest [UForm](https://github.com/unum-cloud/UForm) checkpoints with [UCall](https://github.com/unum-cloud/UCall) for remote procedure calls. All of those projects are open-source, and free for commercial use, [including the demo itself](http://usearch-images.com/). Check them out [on GitHub](https://github.com/ashvardanian/usearch-images), [jump to the evaluation results](#evaluation-results), or continue reading for more details.

## Training Methodology

1. We amalgamated several mid-sized, high-quality datasets: MSCOCO, VG, SBU, CC.
2. Captions were translated using NLLB, ensuring each image was paired with 21 distinct captions.
3. We expanded on the contrastive pre-training concepts from our [previous post](https://www.unum.cloud/blog/efficient-multimodality.md), introducing new techniques to maintain cross-lingual attributes.

## Evaluation Dataset

MSCOCO stands out as the premier multi-modal retrieval evaluation dataset. However, sourcing its manual translations for popular languages is a challenge, and for many languages we target, it’s an impossibility. Thus, we augmented the evaluation dataset synthetically. This time, we diversified our tools to minimize bias:

- Google Translate API: $20 / 1 Million characters.
- Microsoft Translator API: $10 / 1 Million characters.
- Meta NLLB: Free, provided you have the hardware.

The variance between these three evaluation datasets was minimal. Access all [translations and scripts to replicate our benchmarks on GitHub](https://github.com/unum-cloud/coco-sm).

## Evaluation Results

When benchmarking models, we prioritize two core metrics. The first is recall. “Recall @ **𝑥**” essentially measures the likelihood (percentage) of the ground-truth best search result appearing within the top **𝑥** results of the output. For brevity, for every language and **𝑥**, we have averaged results across all translations. Assuming our training data was also augmented with Meta’s NLLB model, we separately list mean recall for every set of translations in the end of the table.

| Language | OpenCLIP @ 1 | UForm @ 1 | OpenCLIP @ 5 | UForm @ 5 | OpenCLIP @ 10 | UForm @ 10 | Speakers |
| - | - | - | - | - | - | - | - |
| Arabic 🇸🇦 | 22.7 | **31.7** | 44.9 | **57.8** | 55.8 | **69.2** | 274 M |
| Armenian 🇦🇲 | 5.6 | **22.0** | 14.3 | **44.7** | 20.2 | **56.0** | 4 M |
| Chinese 🇨🇳 | 27.3 | **32.2** | 51.3 | **59.0** | 62.1 | **70.5** | 1,118 M |
| English 🇺🇸 | **37.8** | 37.7 | 63.5 | **65.0** | 73.5 | **75.9** | 1,452 M |
| French 🇫🇷 | 31.3 | **35.4** | 56.5 | **62.6** | 67.4 | **73.3** | 274 M |
| German 🇩🇪 | 31.7 | **35.1** | 56.9 | **62.2** | 67.4 | **73.3** | 134 M |
| Hebrew 🇮🇱 | 23.7 | **26.7** | 46.3 | **51.8** | 57.0 | **63.5** | 9 M |
| Hindi 🇮🇳 | 20.7 | **31.3** | 42.5 | **57.9** | 53.7 | **69.6** | 602 M |
| Indonesian 🇮🇩 | 26.9 | **30.7** | 51.4 | **57.0** | 62.7 | **68.6** | 199 M |
| Italian 🇮🇹 | 31.3 | **34.9** | 56.7 | **62.1** | 67.1 | **73.1** | 67 M |
| Japanese 🇯🇵 | 27.4 | **32.6** | 51.5 | **59.2** | 62.6 | **70.6** | 125 M |
| Korean 🇰🇷 | 24.4 | **31.5** | 48.1 | **57.8** | 59.2 | **69.2** | 81 M |
| Persian 🇮🇷 | 24.0 | **28.8** | 47.0 | **54.6** | 57.8 | **66.2** | 77 M |
| Polish 🇵🇱 | 29.2 | **33.6** | 53.9 | **60.1** | 64.7 | **71.3** | 41 M |
| Portuguese 🇵🇹 | 31.6 | **32.7** | 57.1 | **59.6** | 67.9 | **71.0** | 257 M |
| Russian 🇷🇺 | 29.9 | **33.9** | 54.8 | **60.9** | 65.8 | **72.0** | 258 M |
| Spanish 🇪🇸 | 32.6 | **35.6** | 58.0 | **62.8** | 68.8 | **73.7** | 548 M |
| Thai 🇹🇭 | 21.5 | **28.7** | 43.0 | **54.6** | 53.7 | **66.0** | 61 M |
| Turkish 🇹🇷 | 25.5 | **33.0** | 49.1 | **59.6** | 60.3 | **70.8** | 88 M |
| Ukranian 🇺🇦 | 26.0 | **30.6** | 49.9 | **56.7** | 60.9 | **68.1** | 41 M |
| Vietnamese 🇻🇳 | 25.4 | **28.3** | 49.2 | **53.9** | 60.3 | **65.5** | 85 M |
| | | | | | | | |
| Mean | 26.5±6.4 | **31.8±3.5** | 49.8±9.8 | **58.1±4.5** | 60.4±10.6 | **69.4±4.3** | - |
| Google Translate | 27.4±6.3 | **31.5±3.5** | 51.1±9.5 | **57.8±4.4** | 61.7±10.3 | **69.1±4.3** | - |
| Microsoft Translator | 27.2±6.4 | **31.4±3.6** | 50.8±9.8 | **57.7±4.7** | 61.4±10.6 | **68.9±4.6** | - |
| Meta NLLB | 24.9±6.7 | **32.4±3.5** | 47.5±10.3 | **58.9±4.5** | 58.2±11.2 | **70.2±4.3** | - |

Summarizing the results:

1. OpenCLIP slightly edges out with a 0.1% higher “recall @ 1”, but falls behind in all other metrics.
2. Languages under-represented in CommonCrawl and other common datasets saw significant improvement.
3. Even the most popular language groups can benefit from data-efficient pre-training techniques.
4. UForm has natural bias towards NLLB, noticeable during evaluation.

Delving into the third point, both Chinese and Hindi experienced a substantial boost, with Hindi’s “recall @ 1” jumping from 20.4% to 30.8%, and its “recall @ 10” soaring from 53.3% to 69.1%. These improvements, however, focus on retrieval tasks, and **don’t** mean you should expect good results on other multi-modal tasks, such as zero-shot ImageNet classification. That, however, is part of our ongoing effort and will be improved in UForm v3.

| | 🇸🇦 | 🇦🇲 | 🇨🇳 | 🇫🇷 | 🇩🇪 | 🇮🇱 | 🇮🇳 | 🇮🇩 | 🇮🇹 | 🇯🇵 | 🇰🇷 | 🇮🇷 | 🇵🇱 | 🇵🇹 | 🇷🇺 | 🇪🇸 | 🇹🇭 | 🇹🇷 | 🇺🇦 | 🇻🇳 |
| - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| OpenCLIP NDCG | 0.639 | 0.204 | 0.731 | 0.823 | 0.806 | 0.657 | 0.616 | 0.733 | 0.811 | 0.737 | 0.686 | 0.667 | 0.764 | 0.832 | 0.777 | 0.849 | 0.606 | 0.701 | 0.704 | 0.697 |
| UForm NDCG | 0.868 | 0.691 | 0.880 | 0.932 | 0.927 | 0.791 | 0.879 | 0.870 | 0.930 | 0.885 | 0.869 | 0.831 | 0.897 | 0.897 | 0.906 | 0.939 | 0.822 | 0.898 | 0.851 | 0.818 |

The second metric we emphasize is the Normalized Discounted Cumulative Gain (NDCG), typically used to assess ranking quality. In the absence of a definitive ground-truth multi-lingual ranking, we use English as a benchmark for other languages. A higher NDCG score indicates more consistent model behavior for a particular language. For a comprehensive view, we evaluate the top 20 results across all languages. On average, the NDCG for OpenCLIP is 0.716±0.149 across 20 languages. For UForm it grows to 0.875±0.064, with higher than 0.9 scores for Spanish, Italian, French, German, and Russian. These results are important step forward in our [quest for better aligned multi-modal representations, which are still horrible, even for 10x larger models trained on 1000x more data](https://ashvardanian.com/posts/searching-stable-marriages/#exploring-uni-modal-representations).

## PyTorch, PopTorch, and Graphcore

In the past, UForm’s inference library was entangled with numerous high-level dependencies, making version transitions unpredictable. We’ve since refactored the core classes down to pure PyTorch. This not only enhances performance but also ensures UForm deployments are more stable than most high-level AI libraries. But we didn’t stop at PyTorch. Recognizing the surge in specialized high-performance AI hardware, we’ve adapted UForm for PopTorch. This means UForm is ready to run on Graphcore IPUs right out of the box, seamlessly handling model-parallelism.

```python
import uform
import poptorch
import PIL as pil

options = poptorch.Options()

model = uform.get_model_ipu('unum-cloud/uform-vl-english')
model = poptorch.inferenceModel(model, options=options)

text = 'a small red panda in a zoo'
image = pil.Image.open('red_panda.jpg')
image_data = model.preprocess_image(image)
text_data = model.preprocess_text(text)

image_features, text_features = model(image_data, text_data)
```

Running on IPUs is akin to operating on GPUs. First, ensure the drivers are correctly set up. Next, download the desired model. Lastly, feed in your data. UForm offers flexibility, allowing for both model-parallel and data-parallel operations. The code snippet below demonstrates how to distribute the model across 4 IPUs. Additionally, it replicates this sharded setup fourfold, aiming to utilize a total of 16 IPUs simultaneously.

```python
options = poptorch.Options()
options.replicationFactor(4)
options.deviceIterations(4)

model = uform.get_model_ipu('unum-cloud/uform-vl-english').parallelize()
model = poptorch.inferenceModel(model, options=options)
```

Similarly, we have ported the model to Apple’s CoreML for mobile inference on iOS, and ONNX for broader adoption. Still, need assistance integrating Semantic Search into your application? Don’t hesitate – [join us on Discord](https://discord.gg/jsMURnSFM2) 🤗
