---
license: apache-2.0
library_name: litert
pipeline_tag: text-classification
language:
- en
tags:
- mediapipe
- litert
- tflite
- text-classification
- on-device
- android
- ios
- web
- python
- flutter
- nlp
- sentiment-analysis
- sst-2
- average-word-embedding
- fp32
---
# MediaPipe Text Classifier (Average Word Embedding)
On-device English sentiment classification model (`average_word_classifier.tflite`, 776 KB) trained on Stanford Sentiment Treebank (SST-2) movie reviews for the [MediaPipe Text Classifier (`TextClassifier`)](https://developers.google.com/edge/mediapipe/solutions/text/text_classifier) task.
Ultra-fast continuous bag-of-words / average word-embedding classifier (`776 KB`, FP32, `[−1, 256]` input) trained on SST-2 (`0` = negative, `1` = positive), embedding a 10,003-entry regex `vocab.txt` (``, ``, ``, plus vocabulary words) and `labels.txt` inside `TFLITE_METADATA`.
## Files
| File | Precision | Size | SHA-256 |
|---|---|---:|---|
| [`average_word_classifier.tflite`](https://huggingface.co/litert-community/MediaPipe-TextClassifier-AverageWord/blob/main/average_word_classifier.tflite) | `float32` | 775.7 KB (775,706 B) | `13bf6f7f35964f1e85d6cc762ee7b1952009b532b233baa5bdb4bf7441097f34` |
### Download
```bash
pip install -U huggingface_hub
hf download litert-community/MediaPipe-TextClassifier-AverageWord average_word_classifier.tflite --local-dir .
```
## Inputs, Outputs, and Model Specifications
### `average_word_classifier.tflite`
- Embedded `TFLITE_METADATA`: name `TextClassifier` · version `1` · author `MediaPipe` · packed associated files: `vocab.txt`, `labels.txt`
| Direction | Tensor | Shape | Type | Notes |
|---|---|---|---|---|
| Input | `serving_default_input_1:0` | `[-1, 256]` | `int32` | input_text — Embedding vectors representing the input text to be processed. |
| Output | `StatefulPartitionedCall:0` | `[-1, 2]` | `float32` | score — Score of the labels respectively. — Labels: `labels.txt` |
## 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-TextClassifier-AverageWord", filename="average_word_classifier.tflite")
BaseOptions = mp.tasks.BaseOptions
TextClassifier = mp.tasks.text.TextClassifier
TextClassifierOptions = mp.tasks.text.TextClassifierOptions
options = TextClassifierOptions(base_options=BaseOptions(model_asset_path=model_path))
with TextClassifier.create_from_options(options) as classifier:
result = classifier.classify("An unforgettable and genuinely moving film!")
for cat in result.classifications[0].categories:
print(f"{cat.category_name}: {cat.score:.3f}")
```
### Cross-Platform Guides & Samples
- **Task overview & options:** [Text Classifier documentation](https://developers.google.com/edge/mediapipe/solutions/text/text_classifier)
- **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_classifier) · [Web Source](https://github.com/google-ai-edge/mediapipe-samples-web/blob/main/src/tasks/text-classifier.ts) · [Android](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/text_classification/android) · [iOS](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/text_classification/ios) · [Python Notebook](https://colab.research.google.com/github/google-ai-edge/mediapipe-samples/blob/main/examples/text_classification/python/text_classifier.ipynb) · [Flutter](https://github.com/google/flutter-mediapipe/tree/main/samples/text/text_classifier)
## Latency Benchmarks
End-to-end MediaPipe Task pipeline average latency reported by the [Text Classifier documentation](https://developers.google.com/edge/mediapipe/solutions/text/text_classifier#benchmarks):
| Model Variant | Device | CPU Latency | GPU Latency |
|---|---|---:|---:|
| Average Word Embedding | Pixel 6 | 0.14 ms | — |
## Intended Use, Limitations, and Fairness
- **Intended applications:** Binary English sentiment analysis (positive vs. negative) on short text snippets such as reviews and feedback.
- **Out-of-scope & limitations:**
- **English only:** Not suitable for non-English text.
- **Domain shift:** Trained on SST-2 movie reviews (`https://nlp.stanford.edu/sentiment/index.html`); accuracy may degrade on unrelated domains, sarcasm, or multi-sentence documents.
- 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 |
|---|---|---|---|---|
| `average_word_classifier.tflite` | [`average_word_classifier.tflite`](https://storage.googleapis.com/mediapipe-models/text_classifier/average_word_classifier/float32/latest/average_word_classifier.tflite) | `1682480023219908` | Wed, 26 Apr 2023 03:33:43 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.