urdu-nlp-tools
Practical Python utilities for Urdu and Roman Urdu NLP: normalization, preprocessing, transliteration, lightweight augmentation, classification metrics, and sentiment analysis.
The default sentiment analyzer is dependency-free and works immediately with a small Urdu/Roman Urdu lexicon. For real research or production work, train it on your own labeled dataset with the optional scikit-learn extra.
Install
pip install urdu-nlp-tools
For TF-IDF + LinearSVC training:
pip install "urdu-nlp-tools[train]"
Quick Start
from urdu_nlp import SentimentAnalyzer
model = SentimentAnalyzer()
print(model.predict("یہ فلم بہت اچھی تھی"))
# positive
Batch prediction:
from urdu_nlp import SentimentAnalyzer
model = SentimentAnalyzer()
labels = model.predict([
"یہ فلم بہت اچھی تھی",
"movie bohat kharab thi",
])
print(labels)
Train Your Own Sentiment Model
CSV files should include a text column and a label column. By default, the helpers expect review and sentiment.
from urdu_nlp import SentimentAnalyzer, load_labeled_csv
records = load_labeled_csv("urdu_reviews.csv")
texts = [record.text for record in records]
labels = [record.label for record in records]
model = SentimentAnalyzer().fit(texts, labels)
model.save("urdu_sentiment.pkl")
loaded = SentimentAnalyzer.from_file("urdu_sentiment.pkl")
print(loaded.predict("یہ فلم بہت اچھی تھی"))
Text Utilities
from urdu_nlp import clean_text, normalize_urdu, roman_to_urdu, tokenize_words
print(normalize_urdu("كيا يہ ۱۲۳ ہے؟"))
print(clean_text("@user movie bohat achi thi!!!"))
print(tokenize_words("یہ فلم بہت اچھی تھی"))
print(roman_to_urdu("bohat achi film"))
Metrics
from urdu_nlp import accuracy_score, classification_report
y_true = ["positive", "negative", "neutral"]
y_pred = ["positive", "negative", "positive"]
print(accuracy_score(y_true, y_pred))
print(classification_report(y_true, y_pred))
CLI
urdu-nlp-sentiment "یہ فلم بہت اچھی تھی"
urdu-nlp-sentiment --model urdu_sentiment.pkl "movie bohat kharab thi"
Package Layout
urdu_nlp/
├── normalize.py
├── sentiment.py
├── transliteration.py
├── augmentation.py
├── preprocessing.py
└── metrics.py
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 urdu_nlp_tools-0.1.2.tar.gz.
File metadata
- Download URL: urdu_nlp_tools-0.1.2.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a8e1aa2a49558f36438a32693b096b90e216964daa8d2e5e851fa792eb3f230
|
|
| MD5 |
25eafb87909c1efd325f2e9cb68296c5
|
|
| BLAKE2b-256 |
eb2b69b9854aa3cd61815bac1b9bd293494a9156459aa01885b4482226b9cb93
|
File details
Details for the file urdu_nlp_tools-0.1.2-py3-none-any.whl.
File metadata
- Download URL: urdu_nlp_tools-0.1.2-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a5399a58e5630b7e2a2b7a992c67622b12d196aa82fbd8a393986683c2c7cb8
|
|
| MD5 |
149fc80207f2348208c09118da273c54
|
|
| BLAKE2b-256 |
a2bb0f068d8d4dfc27317b318b8f18e24a8a3b8f29c5d2e62d66f7352d8e542c
|