Skip to main content

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

Publishing

Publishing is automated with GitHub Actions. Add a repository secret named PYPI_API_TOKEN, then create a GitHub release. The workflow runs the test suite, builds the wheel and source distribution, and publishes both to PyPI. It can also be started manually from the Actions tab.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urdu_nlp_tools-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

urdu_nlp_tools-0.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file urdu_nlp_tools-0.1.0.tar.gz.

File metadata

  • Download URL: urdu_nlp_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for urdu_nlp_tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b88ade3c862e070637d7792337ca9296a9b077b75ecfab2212f0b8108f8e63f
MD5 c7cbd402530a08f0eb54ffd783b882ea
BLAKE2b-256 37ea1b4a7c8494671debe2a966edf6647a5a594cbd7ff1ae7da26f7663f89e72

See more details on using hashes here.

File details

Details for the file urdu_nlp_tools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: urdu_nlp_tools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for urdu_nlp_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d0cdc4f1cee974cd768fc4ec07cb6b9acbe754797af63146061b7b3daf3c731
MD5 d129e78313aa6de0ef66a234f86e72c0
BLAKE2b-256 d9f6cf5d432aa171f6f7db18c9fb20b3f9aec82df86f140aeb08a734de7f9e3f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page