Sentence Similarity
LiteRT
LiteRT
English
mediapipe
on-device
android
ios
web
python
flutter
nlp
sentence-embeddings
universal-sentence-encoder
dual-encoder
fp32
Instructions to use litert-community/MediaPipe-TextEmbedder-Universal-Sentence-Encoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/MediaPipe-TextEmbedder-Universal-Sentence-Encoder with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
File size: 7,507 Bytes
832fd94 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | ---
license: apache-2.0
library_name: litert
pipeline_tag: sentence-similarity
language:
- en
tags:
- mediapipe
- litert
- tflite
- sentence-similarity
- on-device
- android
- ios
- web
- python
- flutter
- nlp
- sentence-embeddings
- universal-sentence-encoder
- dual-encoder
- fp32
---
# MediaPipe Universal Sentence Encoder (Text Embedder)
Compact dual-encoder text embedding model (`universal_sentence_encoder.tflite`, 6.1 MB, FP32) mapping text inputs to **100-dimensional** dense semantic vectors for rapid on-device cosine similarity and topical clustering in the [MediaPipe Text Embedder (`TextEmbedder`)](https://developers.google.com/edge/mediapipe/solutions/text/text_embedder) task.
<div style="border: 1px solid rgba(59, 130, 246, 0.28); background-color: rgba(59, 130, 246, 0.06); border-radius: 8px; padding: 12px 16px; margin: 16px 0;">
<p style="margin: 0 0 6px 0;"><strong>Documentation:</strong> <a href="https://developers.google.com/edge/mediapipe/solutions/text/text_embedder">MediaPipe Text Embedder Docs</a></p>
<p style="margin: 0 0 6px 0;"><strong>Samples:</strong> <a href="https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/text_embedder/android">Android</a> · <a href="https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/text_embedder/ios">iOS</a> · <a href="https://colab.research.google.com/github/google-ai-edge/mediapipe-samples/blob/main/examples/text_embedder/python/text_embedder.ipynb">Python Colab</a> · <a href="https://github.com/google-ai-edge/mediapipe-samples-web/blob/main/src/tasks/text-embedder.ts">Web</a> · <a href="https://github.com/google/flutter-mediapipe/tree/main/samples/text/text_embedder">Flutter</a></p>
<p style="margin: 0;"><strong>Try live:</strong> <a href="https://google-ai-edge.github.io/mediapipe-samples-web/#/text/text_embedder">Web Demo</a></p>
</div>
Uses a compact dual-encoder architecture trained on question-answer datasets (`[-1, 100]` output vector). Captures topical similarity rather than sentiment polarity (for example, `"I like my phone"` and `"I hate my phone"` produce high similarity because both concern phones).
## Files
| File | Precision | Size | SHA-256 |
|---|---|---:|---|
| [`universal_sentence_encoder.tflite`](https://huggingface.co/litert-community/MediaPipe-TextEmbedder-Universal-Sentence-Encoder/blob/main/universal_sentence_encoder.tflite) | `float32` | 6.12 MB (6,120,274 B) | `89ad3c74175dd8caa398cc22b657296d94302d20c525c12b58b29420f7249749` |
### Download
```bash
pip install -U huggingface_hub
hf download litert-community/MediaPipe-TextEmbedder-Universal-Sentence-Encoder universal_sentence_encoder.tflite --local-dir .
```
## Inputs, Outputs, and Model Specifications
### `universal_sentence_encoder.tflite`
- Embedded `TFLITE_METADATA`: name `USE-QA TFLite model` · version `1` · author `MediaPipe`
| Direction | Tensor | Shape | Type | Notes |
|---|---|---|---|---|
| Input | `ParseExample/ParseExampleV2:1` | `[-1]` | `string` | inp_text — Input query text |
| Input | `ParseExample/ParseExampleV2:2` | `[-1]` | `string` | res_context — Input query text |
| Input | `ParseExample/ParseExampleV2:3` | `[-1]` | `string` | res_text — Input query text |
| Output | `Final/EncodeQuery/mul` | `[-1, 100]` | `float32` | query_encoding — query-response similarity. |
| Output | `Final/EncodeResult/mul` | `[-1, 100]` | `float32` | response_encoding — query-response similarity. |
## Use with MediaPipe Tasks
### Python Quickstart
```bash
pip install -U mediapipe huggingface_hub
```
```python
import mediapipe as mp
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(repo_id="litert-community/MediaPipe-TextEmbedder-Universal-Sentence-Encoder", filename="universal_sentence_encoder.tflite")
BaseOptions = mp.tasks.BaseOptions
TextEmbedder = mp.tasks.text.TextEmbedder
TextEmbedderOptions = mp.tasks.text.TextEmbedderOptions
options = TextEmbedderOptions(base_options=BaseOptions(model_asset_path=model_path), quantize=True)
with TextEmbedder.create_from_options(options) as embedder:
e1 = embedder.embed("It's a charming and affecting journey.").embeddings[0]
e2 = embedder.embed("What a great and fantastic trip!").embeddings[0]
print("Cosine similarity:", TextEmbedder.cosine_similarity(e1, e2))
```
### Cross-Platform Guides & Samples
- **Task overview & options:** [Text Embedder documentation](https://developers.google.com/edge/mediapipe/solutions/text/text_embedder)
- **Platform setup guides:** [Python](https://developers.google.com/edge/mediapipe/solutions/setup_python) · [Web / JavaScript](https://developers.google.com/edge/mediapipe/solutions/setup_web) · [Android (Kotlin / Java)](https://developers.google.com/edge/mediapipe/solutions/setup_android) · [iOS (Swift)](https://developers.google.com/edge/mediapipe/solutions/setup_ios) · [Flutter (Dart)](https://developers.google.com/edge/mediapipe/solutions/setup_flutter)
- **Runnable sample apps:** [Web Demo](https://google-ai-edge.github.io/mediapipe-samples-web/#/text/text_embedder) · [Web Source](https://github.com/google-ai-edge/mediapipe-samples-web/blob/main/src/tasks/text-embedder.ts) · [Android](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/text_embedder/android) · [iOS](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/text_embedder/ios) · [Python Notebook](https://colab.research.google.com/github/google-ai-edge/mediapipe-samples/blob/main/examples/text_embedder/python/text_embedder.ipynb) · [Flutter](https://github.com/google/flutter-mediapipe/tree/main/samples/text/text_embedder)
## Latency Benchmarks
Average CPU pipeline latency reported by the [Text Embedder documentation](https://developers.google.com/edge/mediapipe/solutions/text/text_embedder#benchmarks):
| Model Variant | Device | CPU Latency |
|---|---|---:|
| Universal Sentence Encoder | Galaxy S26 Ultra (4 threads) | 10 ms |
## Intended Use, Limitations, and Fairness
- **Intended applications:** Lightweight on-device semantic similarity, FAQ/retrieval matching, and topical grouping where minimal size (6.1 MB) and ≈10 ms CPU latency are prioritized over 768D LLM embeddings.
- **Limitations & considerations:** Dual-encoder trained on QA pairs; for multilingual or instruction-steered retrieval/classification tasks, consider `MediaPipe-TextEmbedder-EmbeddingGemma-300M`. No standalone Google fairness PDF is published for this model on the MediaPipe documentation page.
## Provenance
Every model binary in this repository is byte-identical (unmodified FlatBuffer weights and embedded `TFLITE_METADATA` bytes) to the official artifact served by Google from `storage.googleapis.com/mediapipe-models`.
| Repo File | Upstream URL | GCS Generation | Upstream `Last-Modified` | Pinned Bucket Version |
|---|---|---|---|---|
| `universal_sentence_encoder.tflite` | [`universal_sentence_encoder.tflite`](https://storage.googleapis.com/mediapipe-models/text_embedder/universal_sentence_encoder/float32/latest/universal_sentence_encoder.tflite) | `1682480025114200` | Wed, 26 Apr 2023 03:33:45 GMT | `/1/` |
## License and Citation
- License: `apache-2.0` — Distributed under Apache License, Version 2.0 alongside the [MediaPipe](https://github.com/google-ai-edge/mediapipe) release artifacts.
### Citation
Architecture linked from the MediaPipe Text Embedder documentation: [`aclanthology.org/2022.emnlp-main.640.pdf`](https://aclanthology.org/2022.emnlp-main.640.pdf).
|