Skip to main content

urdu-nlp-tools

Open In Colab

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

urdu_nlp_tools-0.1.1.tar.gz (14.1 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.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: urdu_nlp_tools-0.1.1.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

Hashes for urdu_nlp_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 304ead7a16ca49672498a4a60aedb6c115ff1e4aa0f1bcfc55547bb63521a891
MD5 504dcb35248b76c3713d1674b482fcb8
BLAKE2b-256 b6129da1d504545b3fa2356ab25681d397d2575ec16018f260e7b758c5b3ae95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: urdu_nlp_tools-0.1.1-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

Hashes for urdu_nlp_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88a4d70c035dace89a466eff768b1b03bb5d627933187f92b6c6e04cfb624d11
MD5 c9a6479717c899714198ba5973da0596
BLAKE2b-256 411d56c3ec061137b76b185ea42f3e378c83b1ba166918c86ad4602221c24edc

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

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