Instructions to use litert-community/MediaPipe-TextClassifier-MobileBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/MediaPipe-TextClassifier-MobileBERT 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
Download README.md from litert-community/MediaPipe-TextClassifier-MobileBERT: direct link, hf CLI and curl.
- Browser
- Download file 7.73 kB
-
https://huggingface.co/litert-community/MediaPipe-TextClassifier-MobileBERT/resolve/main/README.md
- Command line
-
hf download hf://litert-community/MediaPipe-TextClassifier-MobileBERT/README.md
-
curl -L -o README.md https://huggingface.co/litert-community/MediaPipe-TextClassifier-MobileBERT/resolve/main/README.md
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
- mobilebert
- sentiment-analysis
- sst-2
- dynamic-range
- arxiv:2004.02984
MediaPipe Text Classifier (MobileBERT)
On-device English sentiment classification model (bert_classifier.tflite, 25.7 MB) trained on Stanford Sentiment Treebank (SST-2) movie reviews for the MediaPipe Text Classifier (TextClassifier) task.
Documentation: MediaPipe Text Classifier Docs
Samples: Android · iOS · Python Colab · Web · Flutter
Try live: Web Demo
MobileBERT sequence classifier fine-tuned on SST-2 (negative, positive), dynamic-range quantized with embedded BERT vocab.txt and labels.txt in TFLITE_METADATA (performing out-of-graph WordPiece tokenization into 128-token word_ids, type_ids, and mask inputs).
Files
| File | Precision | Size | SHA-256 |
|---|---|---|---|
bert_classifier.tflite |
dynamic-range |
25.71 MB (25,707,538 B) | 9b45012ab143d88d61e10ea501d6c8763f7202b86fa987711519d89bfa2a88b1 |
Download
pip install -U huggingface_hub
hf download litert-community/MediaPipe-TextClassifier-MobileBERT bert_classifier.tflite --local-dir .
Inputs, Outputs, and Model Specifications
bert_classifier.tflite
- Embedded
TFLITE_METADATA: nameMobileBert text classifier· version1· authorMediaPipe· packed associated files:vocab.txt,labels.txt
| Direction | Tensor | Shape | Type | Notes |
|---|---|---|---|---|
| Input | serving_default_input_word_ids:0 |
[1, 128] |
int32 |
ids — Tokenized ids of input text as concatenated query and passage. |
| Input | serving_default_input_type_ids:0 |
[1, 128] |
int32 |
segment_ids — 0 for query and 1 for passage tokens. |
| Input | serving_default_input_mask:0 |
[1, 128] |
int32 |
mask — Mask with 1 for real tokens and 0 for padding tokens. |
| Output | StatefulPartitionedCall:0 |
[1, 2] |
float32 |
probability — Probabilities of labels respectively. — Labels: labels.txt |
Use with MediaPipe Tasks
Python Quickstart
pip install -U mediapipe huggingface_hub
import mediapipe as mp
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(repo_id="litert-community/MediaPipe-TextClassifier-MobileBERT", filename="bert_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
- Platform setup guides: Python · Web / JavaScript · Android (Kotlin / Java) · iOS (Swift) · Flutter (Dart)
- Runnable sample apps: Web Demo · Web Source · Android · iOS · Python Notebook · Flutter
Latency Benchmarks
End-to-end MediaPipe Task pipeline average latency reported by the Text Classifier documentation:
| Model Variant | Device | CPU Latency | GPU Latency |
|---|---|---|---|
| MobileBERT | Pixel 6 | 57.68 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 |
|---|---|---|---|---|
bert_classifier.tflite |
bert_classifier.tflite |
1682480022043445 |
Wed, 26 Apr 2023 03:33:42 GMT | /1/ |
License and Citation
- License:
apache-2.0— Stated as Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) in the embeddedTFLITE_METADATAblock of the.tflitemodel file(s).
Citation
@inproceedings{sun2020mobilebert,
title = {MobileBERT: a Compact Task-Agnostic BERT for Resource-Limited Devices},
author = {Sun, Zhiqing and Yu, Hongkun and Song, Xiaodan and Liu, Renjie and Yang, Yiming and Zhou, Denny},
booktitle = {Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics (ACL)},
year = {2020},
url = {https://arxiv.org/abs/2004.02984}
}