Artificial Intelligence & Machine Learning
Urdu to Roman Urdu Neural Machine Translation - BiLSTM Seq2Seq
A neural machine translation project that converts Urdu text written in Perso-Arabic script into Roman Urdu using a custom Bidirectional LSTM (BiLSTM) encoder–decoder architecture built with PyTorch. Designed around Urdu Ghazal text, the system explores text normalization, transliteration, sequence-to-sequence learning, and evaluation using BLEU, perplexity, and Character Error Rate (CER).
The challenge
Urdu transliteration involves mapping a language written in Perso-Arabic script into Roman Urdu while preserving pronunciation and readability. Differences in spelling conventions, character variations, and the lack of consistently transliterated parallel data make the task challenging, especially for poetic text. The objective is to build a neural sequence model that learns transliteration patterns from Urdu and Roman Urdu sentence pairs.
Context
This project explores neural sequence-to-sequence learning using an Urdu Ghazal dataset from the urdu_ghazals_rekhta repository. A custom BiLSTM encoder processes Urdu input sequences, while an LSTM decoder generates the corresponding Roman Urdu output. The workflow includes text normalization, tokenization, dataset preparation, model training, and quantitative evaluation.
The solution
Developed a PyTorch-based encoder–decoder pipeline for Urdu-to-Roman-Urdu transliteration. The preprocessing workflow normalizes Urdu characters, cleans text, and prepares paired sequences for model training. The bidirectional encoder captures information from both directions of the input sequence, while the LSTM decoder generates Roman Urdu tokens sequentially. A Streamlit interface provides a convenient way to enter Urdu text and inspect the generated transliteration.
Design
The architecture separates input representation, sequence encoding, decoding, and output processing. Embedding layers convert tokens into dense representations, and the BiLSTM encoder captures contextual information across the input. The decoder learns to generate the output sequence using teacher forcing during training. Optional attention and subword tokenization can be explored to improve alignment and handle unfamiliar words.
Architecture
- Framework: PyTorch
- Model: Sequence-to-Sequence (Seq2Seq)
- Encoder: Bidirectional LSTM (BiLSTM)
- Decoder: LSTM
- Embeddings: Trainable token embeddings
- Regularization: Dropout
- Training Technique: Teacher forcing
- Loss Function: Cross-entropy loss
- Optimizer: Adam
- Dataset: urdu_ghazals_rekhta
- Evaluation: BLEU, perplexity, and Character Error Rate (CER)
Development
The development workflow includes dataset exploration, Urdu text normalization, creation of Urdu–Roman Urdu pairs, tokenization, and preparation of training, validation, and test sets. The model is trained with configurable embedding dimensions, hidden sizes, layer counts, dropout, learning rates, and batch sizes. Evaluation scripts compare model predictions with reference transliterations, while the Streamlit application connects the trained checkpoint to an interactive interface.
Results
The project establishes a framework for experimenting with neural transliteration of Urdu poetic text into Roman Urdu. Example outputs can be compared with reference transliterations to identify spelling differences and measure character-level accuracy. BLEU, perplexity, and CER provide complementary evaluation perspectives. Final performance figures should be added using actual experiment results rather than assumed values.