MediaPipe-TextClassifier-AverageWord
lightning-fast sentiment classifier
2 min readupdated
A compact English-language model based on the average word embedding architecture, packaged in a .tflite file of just 776 KB. It is trained on the SST-2 movie review dataset and designed for binary text sentiment evaluation (identifying positive and negative reviews). The model is built for the Google MediaPipe ecosystem and can run directly on mobile devices or in the browser. It is a great fit for developers who need to integrate sentiment analysis into a mobile, web, or desktop app quickly and without heavy AI models.
Key features
- Tiny size: The model weighs only 776 KB (FP32 format), making it easy to embed into client applications.
- High operating speed: On a Google Pixel 6 device, the average CPU latency is just 0.14 ms.
- Built-in metadata: A vocabulary of 10,003 tokens (
vocab.txt) and a label file (labels.txt) are already packed insideTFLITE_METADATA. - Cross-platform: Full support through the MediaPipe framework for Python, JavaScript, Android, iOS, and Flutter.
What you can do
- Mobile app integration: Quickly evaluate the sentiment of user reviews or messages locally on Android or iOS.
- Web analysis in the browser: Process short user input directly on the client side without sending requests to a server.
- Text analysis in Python: Quickly classify reviews, comments, or short text snippets in scripts.
Example
Code example for text classification using Python and the mediapipe library:
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}")Read more
DetailsBenchmarks: CPU latency on Pixel 6 — 0.14 ms
Hardware requirements: ultra-lightweight model for running on mobile and PC CPUs
Limitations: English language only; potential accuracy degradation on classifieds, sarcasm, or long multi-sentence texts
License: Apache-2.0










Comments