A lightweight Nigerian-focused intent classifier using SpaCy and PyTorch
Project description
Uni9ja Intent Classifier
A lightweight, high-performance Intent Classification library built on PyTorch and SpaCy. This library allows you to identify user intentions in text using word embeddings.
🛠 Features
- Three-Mode Logic: Use our pretrained model, fine-tune it with your data, or train a new one from scratch.
- SpaCy Integration: Uses
en_core_web_mdfor high-quality semantic vectors. - Auto-Adaptive Architecture: Automatically rebuilds the model head if you add new intent categories during fine-tuning.
- Production Ready: Includes Early Stopping, Learning Rate Scheduling, and Dropout for regularization.
Installation
- Clone the repository:
git clone https://github.com/Perfect-Aimers-Enterprise/uni9ja_nlp.git
cd uni9ja_intent
- Install the library:
pip install uni9ja-intent
- Download the language model:
python -m spacy download en_core_web_md
Usage Guide
1. Using the Pretrained Model (Inference)
If you just want to use the model out of the box to predict intents:
from uni9ja_intent import IntentModel
# Initialize and load weights
model = IntentModel()
model.load_model("pretrained/uni9ja_intent.pth")
# Predict
intent, confidence = model.predict("How do I sign up for the project?")
print(f"Intent: {intent} ({confidence:.2%})")
2. Fine-tuning with New Data
Use this when you want the model to keep its old knowledge but learn a few new phrases or categories.
new_data = [
{"text": "I want to hire a freelancer", "label": "hire_request"},
{"text": "Is there a discount for students?", "label": "pricing_query"}
]
model.finetune(new_data, epochs=20, save_path="pretrained/uni9ja_intent_v2.pth")
3. Training from Scratch (Custom Logic)
Use this if you have a completely different dataset and want to build a brand new brain.
my_custom_data = [
{"text": "What is the weather?", "label": "weather"},
{"text": "Play some music", "label": "media_control"},
# ... more data
]
# Passing data to __init__ triggers the training setup
model = IntentModel(data=my_custom_data, hidden_dims=[256, 128], dropout=0.4)
model.train(epochs=100)
model.save_model("my_custom_model.pth")
Project Structure
.
├── pretrained/ # Saved .pth model checkpoints
├── uni9ja_intent/ # Core Library Source
│ ├── __init__.py # Package entry point
│ ├── model.py # PyTorch Neural Network Architecture
│ ├── trainer.py # IntentModel Manager Class
│ └── spacy_loader.py # Vectorization logic
├── setup.py # Pip installation script
└── requirements.txt # Dependencies
Configuration Parameters
| Parameter | Default | Description |
|---|---|---|
hidden_dims |
[128, 64] |
The size of the hidden layers in the MLP. |
dropout |
0.3 |
Probability of dropping neurons (prevents overfitting). |
threshold |
0.6 |
Minimum confidence score to return a label. |
Pro-Tip for Terminal Users
To see your folder structure like the one in this documentation, remember to use the command we set up earlier:
tree -I '__pycache__|.git'
Would you like me to create a test.py script for you that automatically verifies if all these features are working correctly?
Loading Data in Code
You can now load your files directly using the built-in utility:
Python from uni9ja_intent import IntentModel, load_data
1. Load data from file
training_data = load_data("path/to/your_data.json")
2. Feed it to the model
model = IntentModel(data=training_data) model.train(epochs=50)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uni9ja_intent-0.1.4.tar.gz.
File metadata
- Download URL: uni9ja_intent-0.1.4.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9f03f7a6df5e015bb1439851e72962c5708115c9e3ca9dcf868ccc58f253e27
|
|
| MD5 |
1c27ccb4b82e6931f1450c4d49682757
|
|
| BLAKE2b-256 |
9222686cfb28d3ee8514dfca390906c1b51764a9ed9a95f700b0fd7ad661d563
|
File details
Details for the file uni9ja_intent-0.1.4-py3-none-any.whl.
File metadata
- Download URL: uni9ja_intent-0.1.4-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b1dcdbb233058a2900822532bcacf56323d26dc3a8571a31ca57a00dc22169e
|
|
| MD5 |
bb311536de7e17cd59b6d7997c67b092
|
|
| BLAKE2b-256 |
7edadeac732e50cf8797fede05b77018dd8fcba052bbb43bd754e4cec3ada7c0
|