{"id":30669582,"url":"https://github.com/boltuix/tflite-text-classifier-android-app","last_synced_at":"2025-09-02T02:03:28.502Z","repository":{"id":311706918,"uuid":"1044667211","full_name":"BoltUIX/TFLite-Text-Classifier-Android-App","owner":"BoltUIX","description":"This Android app leverages a TensorFlow Lite model for on-device classification of social media posts into 11 categories, including technology, sports, finance, and more. Built with Kotlin and Jetpack Compose, it ensures efficient, privacy-focused inference without server dependencies.","archived":false,"fork":false,"pushed_at":"2025-08-26T04:27:01.000Z","size":1677,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-26T05:32:58.314Z","etag":null,"topics":["ai","android","appdev","colab-notebook","jetpack-compose","jetpackcompose","kotlin","machine-learning","mobile-app","nlp","on-device","tensorflow","tensorflow-lite","text-classification","tflite","tflite-models","tips-and-tricks"],"latest_commit_sha":null,"homepage":"https://www.boltuix.com/2025/08/how-to-use-tensorflow-lite-for-text.html","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BoltUIX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-26T03:21:03.000Z","updated_at":"2025-08-26T04:59:58.000Z","dependencies_parsed_at":"2025-08-26T05:33:00.091Z","dependency_job_id":"ed9326cf-84e6-4362-8716-f55f35eb66bd","html_url":"https://github.com/BoltUIX/TFLite-Text-Classifier-Android-App","commit_stats":null,"previous_names":["boltuix/tflite-text-classifier-android-app"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/BoltUIX/TFLite-Text-Classifier-Android-App","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoltUIX%2FTFLite-Text-Classifier-Android-App","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoltUIX%2FTFLite-Text-Classifier-Android-App/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoltUIX%2FTFLite-Text-Classifier-Android-App/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoltUIX%2FTFLite-Text-Classifier-Android-App/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BoltUIX","download_url":"https://codeload.github.com/BoltUIX/TFLite-Text-Classifier-Android-App/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoltUIX%2FTFLite-Text-Classifier-Android-App/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273064818,"owners_count":25039264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","android","appdev","colab-notebook","jetpack-compose","jetpackcompose","kotlin","machine-learning","mobile-app","nlp","on-device","tensorflow","tensorflow-lite","text-classification","tflite","tflite-models","tips-and-tricks"],"created_at":"2025-09-01T01:39:30.124Z","updated_at":"2025-09-01T01:39:30.837Z","avatar_url":"https://github.com/BoltUIX.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TFLite Text Classifier Android App\n![How to Use TensorFlow Lite for Text Classification in Jetpack Compose](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxW1gOAZgRe8G3nD_Pw4quU5b4AK3ensLRIEWL04WwJHst17xzAKKNZBDCiMFpU3MG5imsmGQ8CnOJJzMWbQwvwWXopMjW-F13HjwsciXKsP-5XQe3S-iQW3LzqQLzpPrGg04J46rAgqChnsJeC0LF0fAvLpOGgv4IftvutkYbbfMGqNU7HYyFbPbMSyI/s16000/How%20to%20Use%20TensorFlow%20Lite%20for%20Text%20Classification%20in%20Jetpack%20Compose.png)\n\n------------------------------------------------------------------------\n\nThis Android app leverages a TensorFlow Lite model for on-device\nclassification of social media posts into 10+ categories, including\ntechnology, sports, finance, and more. Built with Kotlin and Jetpack\nCompose, it ensures efficient, privacy-focused inference without server\ndependencies.\n\n[![License:\nMIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n[![TensorFlow\nLite](https://img.shields.io/badge/TensorFlow-Lite-blue.svg)](https://www.tensorflow.org/lite)\n\n[![Kotlin](https://img.shields.io/badge/Kotlin-1.9-blueviolet.svg)](https://kotlinlang.org/)\n\n[![Jetpack\nCompose](https://img.shields.io/badge/Jetpack-Compose-green.svg)](https://developer.android.com/jetpack/compose)\n\n[![Android](https://img.shields.io/badge/Android-14+-brightgreen.svg)](https://developer.android.com/)\n\n------------------------------------------------------------------------\n\n## Features\n\n-    **On-device classification** using TensorFlow Lite\n-    **Jetpack Compose UI** for modern Android apps\n-    **Multi-line input** for flexible text entry\n-    **Probability distribution** for each category\n-    **Fast \u0026 lightweight inference** with no server calls\n-    **Manual tokenizer** with `vocab.txt` for reproducibility\n\n------------------------------------------------------------------------\n\n## Training Notebook -- `model.ipynb`\n\nThe repository includes a Jupyter notebook **`Android.ipynb`**,\ncontaining the full **training pipeline** for the classifier:\n\n-    Load \u0026 preprocess training data\n-    Tokenization with `TextVectorization`\n-    Build \u0026 train a Keras model\n-    Convert the model to `.tflite` format\n-    Export `vocab.txt` and `labels.txt` for Android usage\n\nUse this notebook to retrain or fine-tune your model while ensuring\n**consistency** between training and deployment.\n\n------------------------------------------------------------------------\n\n## Model Overview\n\n-   **Model file**: `model_with_softmax.tflite`\n-   **Input**: `int32[1, 50]` → tokenized \u0026 padded sequence\n-   **Output**: `float32[1, 10]` → probability vector (softmax)\n-   **Tokenizer**: `vocab.txt` from training (`TextVectorization`)\n-   **Labels**: `labels.txt` with 11 categories\n\n------------------------------------------------------------------------\n\n## Folder Structure\n\n    app/\n     ├── assets/\n     │     ├── model_with_softmax.tflite\n     │     ├── vocab.txt\n     │     └── labels.txt\n     └── res/\n           └── layout/ (if legacy XML UI is present)\n\n------------------------------------------------------------------------\n\n## Setup Instructions\n\n1.  Add dependencies in `build.gradle`:\n\n``` gradle\nimplementation 'org.tensorflow:tensorflow-lite:2.12.0'\nimplementation 'org.tensorflow:tensorflow-lite-support:0.3.1'\n```\n\n2.  Copy required files to `app/src/main/assets/`:\n   -   `model_with_softmax.tflite`\n   -   `vocab.txt`\n   -   `labels.txt`\n3.  Initialize the classifier in Kotlin:\n\n``` kotlin\nTextClassifier.initialize(context)\n```\n\n------------------------------------------------------------------------\n\n## Example Usage (Jetpack Compose)\n\n``` kotlin\nval text by remember { mutableStateOf(\"\") }\n\nColumn {\n    TextField(\n        value = text,\n        onValueChange = { text = it },\n        placeholder = { Text(\"Enter your post...\") },\n        modifier = Modifier\n            .fillMaxWidth()\n            .height(150.dp),\n        maxLines = 5\n    )\n\n    Button(onClick = {\n        val result = TextClassifier.predictAll(text)\n        val formatted = result.joinToString(\"\\n\") { (label, prob) -\u003e\n            \"$label: ${\"%.2f\".format(prob * 100)}%\"\n        }\n        Log.d(\"Prediction\", formatted)\n    }) {\n        Text(\"Classify\")\n    }\n}\n```\n\n------------------------------------------------------------------------\n\n## Notes\n\n-   The `.tflite` model **must include softmax**\n-   `vocab.txt` and `labels.txt` must match training data\n-   Assets must be placed in `app/src/main/assets/` (not `res/`)\n-   Use `coerceIn()` to ensure predictions remain between `0–1`\n\n------------------------------------------------------------------------\n\n## License\n\nMIT --- Free to use, modify, and distribute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboltuix%2Ftflite-text-classifier-android-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboltuix%2Ftflite-text-classifier-android-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboltuix%2Ftflite-text-classifier-android-app/lists"}