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
Commit ·
832fd94
0
Parent(s):
Initial upload of MediaPipe-TextEmbedder-Universal-Sentence-Encoder from MediaPipe Solutions
Browse files- .gitattributes +38 -0
- README.md +122 -0
- universal_sentence_encoder.tflite +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.litertlm filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.task filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: litert
|
| 4 |
+
pipeline_tag: sentence-similarity
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
tags:
|
| 8 |
+
- mediapipe
|
| 9 |
+
- litert
|
| 10 |
+
- tflite
|
| 11 |
+
- sentence-similarity
|
| 12 |
+
- on-device
|
| 13 |
+
- android
|
| 14 |
+
- ios
|
| 15 |
+
- web
|
| 16 |
+
- python
|
| 17 |
+
- flutter
|
| 18 |
+
- nlp
|
| 19 |
+
- sentence-embeddings
|
| 20 |
+
- universal-sentence-encoder
|
| 21 |
+
- dual-encoder
|
| 22 |
+
- fp32
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# MediaPipe Universal Sentence Encoder (Text Embedder)
|
| 26 |
+
|
| 27 |
+
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.
|
| 28 |
+
|
| 29 |
+
<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;">
|
| 30 |
+
<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>
|
| 31 |
+
<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>
|
| 32 |
+
<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>
|
| 33 |
+
</div>
|
| 34 |
+
|
| 35 |
+
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).
|
| 36 |
+
|
| 37 |
+
## Files
|
| 38 |
+
|
| 39 |
+
| File | Precision | Size | SHA-256 |
|
| 40 |
+
|---|---|---:|---|
|
| 41 |
+
| [`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` |
|
| 42 |
+
|
| 43 |
+
### Download
|
| 44 |
+
|
| 45 |
+
```bash
|
| 46 |
+
pip install -U huggingface_hub
|
| 47 |
+
hf download litert-community/MediaPipe-TextEmbedder-Universal-Sentence-Encoder universal_sentence_encoder.tflite --local-dir .
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Inputs, Outputs, and Model Specifications
|
| 51 |
+
|
| 52 |
+
### `universal_sentence_encoder.tflite`
|
| 53 |
+
|
| 54 |
+
- Embedded `TFLITE_METADATA`: name `USE-QA TFLite model` · version `1` · author `MediaPipe`
|
| 55 |
+
|
| 56 |
+
| Direction | Tensor | Shape | Type | Notes |
|
| 57 |
+
|---|---|---|---|---|
|
| 58 |
+
| Input | `ParseExample/ParseExampleV2:1` | `[-1]` | `string` | inp_text — Input query text |
|
| 59 |
+
| Input | `ParseExample/ParseExampleV2:2` | `[-1]` | `string` | res_context — Input query text |
|
| 60 |
+
| Input | `ParseExample/ParseExampleV2:3` | `[-1]` | `string` | res_text — Input query text |
|
| 61 |
+
| Output | `Final/EncodeQuery/mul` | `[-1, 100]` | `float32` | query_encoding — query-response similarity. |
|
| 62 |
+
| Output | `Final/EncodeResult/mul` | `[-1, 100]` | `float32` | response_encoding — query-response similarity. |
|
| 63 |
+
|
| 64 |
+
## Use with MediaPipe Tasks
|
| 65 |
+
|
| 66 |
+
### Python Quickstart
|
| 67 |
+
|
| 68 |
+
```bash
|
| 69 |
+
pip install -U mediapipe huggingface_hub
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
import mediapipe as mp
|
| 74 |
+
from huggingface_hub import hf_hub_download
|
| 75 |
+
|
| 76 |
+
model_path = hf_hub_download(repo_id="litert-community/MediaPipe-TextEmbedder-Universal-Sentence-Encoder", filename="universal_sentence_encoder.tflite")
|
| 77 |
+
|
| 78 |
+
BaseOptions = mp.tasks.BaseOptions
|
| 79 |
+
TextEmbedder = mp.tasks.text.TextEmbedder
|
| 80 |
+
TextEmbedderOptions = mp.tasks.text.TextEmbedderOptions
|
| 81 |
+
|
| 82 |
+
options = TextEmbedderOptions(base_options=BaseOptions(model_asset_path=model_path), quantize=True)
|
| 83 |
+
with TextEmbedder.create_from_options(options) as embedder:
|
| 84 |
+
e1 = embedder.embed("It's a charming and affecting journey.").embeddings[0]
|
| 85 |
+
e2 = embedder.embed("What a great and fantastic trip!").embeddings[0]
|
| 86 |
+
print("Cosine similarity:", TextEmbedder.cosine_similarity(e1, e2))
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### Cross-Platform Guides & Samples
|
| 90 |
+
|
| 91 |
+
- **Task overview & options:** [Text Embedder documentation](https://developers.google.com/edge/mediapipe/solutions/text/text_embedder)
|
| 92 |
+
- **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)
|
| 93 |
+
- **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)
|
| 94 |
+
|
| 95 |
+
## Latency Benchmarks
|
| 96 |
+
|
| 97 |
+
Average CPU pipeline latency reported by the [Text Embedder documentation](https://developers.google.com/edge/mediapipe/solutions/text/text_embedder#benchmarks):
|
| 98 |
+
|
| 99 |
+
| Model Variant | Device | CPU Latency |
|
| 100 |
+
|---|---|---:|
|
| 101 |
+
| Universal Sentence Encoder | Galaxy S26 Ultra (4 threads) | 10 ms |
|
| 102 |
+
|
| 103 |
+
## Intended Use, Limitations, and Fairness
|
| 104 |
+
|
| 105 |
+
- **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.
|
| 106 |
+
- **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.
|
| 107 |
+
|
| 108 |
+
## Provenance
|
| 109 |
+
|
| 110 |
+
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`.
|
| 111 |
+
|
| 112 |
+
| Repo File | Upstream URL | GCS Generation | Upstream `Last-Modified` | Pinned Bucket Version |
|
| 113 |
+
|---|---|---|---|---|
|
| 114 |
+
| `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/` |
|
| 115 |
+
|
| 116 |
+
## License and Citation
|
| 117 |
+
|
| 118 |
+
- License: `apache-2.0` — Distributed under Apache License, Version 2.0 alongside the [MediaPipe](https://github.com/google-ai-edge/mediapipe) release artifacts.
|
| 119 |
+
|
| 120 |
+
### Citation
|
| 121 |
+
|
| 122 |
+
Architecture linked from the MediaPipe Text Embedder documentation: [`aclanthology.org/2022.emnlp-main.640.pdf`](https://aclanthology.org/2022.emnlp-main.640.pdf).
|
universal_sentence_encoder.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:89ad3c74175dd8caa398cc22b657296d94302d20c525c12b58b29420f7249749
|
| 3 |
+
size 6120274
|