A lightweight machine learning system that detects the language of short text inputs in English, Swahili, Sheng, and Dholuo using TF-IDF and classification models.
# LID β Language Identification System
A lightweight machine learning system that detects the language of short text inputs in **English, Swahili, Sheng, and Dholuo**.
Built for real-world Kenyan digital communication where messages are short, informal, and often multilingual.
---
## Features
- Detects language from short text (1β2 sentences)
- Supports English, Swahili, Sheng, and Dholuo
- Uses TF-IDF with character n-grams
- High accuracy (~95%)
- Real-time predictions via Streamlit app
- Confidence score for each prediction
---
## Dataset Summary
The dataset was manually curated to reflect real-world communication patterns.
- **Total Samples:** 3,021
### Language Distribution
| Language | Samples |
| -------- | ------- |
| English | 991 |
| Swahili | 880 |
| Sheng | 717 |
| Dholuo | 433 |
The dataset consists of short, informal text collected from social media, SMS-style messages, and conversational phrases.
---
## π§ How the Model Works
1. **Preprocessing**
- Lowercasing
- Noise removal
- Cleaning informal text
2. **Feature Extraction**
- TF-IDF vectorization
- Character n-grams (2β4)
3. **Models Used**
- Naive Bayes
- Logistic Regression (Best Model)
4. **Evaluation Metrics**
- Accuracy
- Precision
- Recall
- F1-score
---
## π Project Structure
```text
LID/
βββ app.py
βββ train_model.py
βββ requirements.txt
βββ README.md
βββ data/
βββ utils/
## How to Run
pip install -r requirements.txt
3. Start the app:
streamlit run app.py
## Re-Train the Model
python -m pip install --upgrade pip
python -m pip install pandas scikit-learn streamlit matplotlib
python -c "import sys; print(sys.executable)"
python train_model.py
```