Downloads · 30 days
0
zaiffi/Mehfil-e-Sukhan
Mehfil-e-Sukhan is a text generation model from zaiffi. Use it when you need the model to write or continue text. It is set up for pytorch. The card lists the license as apache-2.0.
A bidirectional LSTM neural network for generating Roman Urdu poetry, fine-tuned on a curated dataset of Urdu poetry in Latin script.
Downloads · 30 days
0
Access
Public
Updated Mar 17, 2025
Repo size
244 MB
Likes
0
Public
Click a slice to open those files.
.pth243 MB · 99%
From the Hugging Face model README
A bidirectional LSTM neural network for generating Roman Urdu poetry, fine-tuned on a curated dataset of Urdu poetry in Latin script.

Mehfil-e-Sukhan (meaning "Poetry Gathering" in Urdu) is a natural language generation model specifically designed for Roman Urdu poetry creation. This repository contains the complete model implementation, including data preprocessing, tokenization, model architecture, training code, and inference utilities.
The model uses a Bidirectional LSTM architecture trained on a dataset of approximately 1,300 lines of Roman Urdu poetry to learn patterns, rhythms, and stylistic elements of Urdu poetry written in Latin script.
The repository contains the following key files:
poetry_generation.ipynb: Complete notebook with data preparation, model definition, training code, and generation utilitiesmodel_weights.pth: Trained model weights (243 MB)urdu_sp.model: SentencePiece tokenizer model (429 KB)urdu_sp.vocab: SentencePiece vocabulary file (181 KB)all_texts.txt: Preprocessed dataset used for training (869 KB)requirements.txt: Required Python packages.gitattributes: Git LFS tracking for large filesThe poetry generation model uses a Bidirectional LSTM architecture:
This architecture was chosen to capture both preceding and following context in poetry lines, which is essential for maintaining coherence and style in the generated text.
The model is trained on the Roman Urdu Poetry dataset, which contains approximately 1,300 lines of Urdu poetry written in Latin script (Roman Urdu). The dataset includes works from various poets and covers a range of poetic styles and themes.
Dataset Source: Roman Urdu Poetry Dataset on Kaggle
Raw poetry lines undergo several preprocessing steps:
The tokenization approach allows the model to handle out-of-vocabulary words by breaking them into subword units, which is particularly important for Roman Urdu where spelling variations are common.
The model was trained with the following parameters:
Training was performed on both CPU and GPU environments, with automatic device detection.
Poetry generation uses nucleus sampling (top-p) with adjustable parameters:
This sampling approach balances creativity and coherence in the generated text, allowing for controlled variation in the output.

The final model achieves a test loss of approximately 3.17, which is reasonable considering the dataset size. The model demonstrates the ability to:
The limited dataset size (1,300 lines) does result in some repetitiveness in longer generations, which could be improved with additional training data.
To use the model for generating poetry:
# Import required libraries (these are included in the notebook)
import torch
import sentencepiece as spm
# Load the SentencePiece model
sp = spm.SentencePieceProcessor()
sp.load("urdu_sp.model")
# Load the BiLSTM model
model = BiLSTMLanguageModel(vocab_size=sp.get_piece_size(),
embed_dim=512,
hidden_dim=768,
num_layers=3,
dropout=0.2)
model.load_state_dict(torch.load("model_weights.pth", map_location=device))
model.eval()
# Generate poetry
start_word = "ishq" # Example: "love"
generated_poetry = generate_poetry_nucleus(model, sp, start_word,
num_words=12,
temperature=1.2,
top_p=0.85)
print(generated_poetry)
An interactive demo of this model is available as a Streamlit application, which provides a user-friendly interface to generate Roman Urdu poetry with adjustable parameters:
Mehfil-e-Sukhan Demo on HuggingFace Spaces
The Streamlit app allows users to:
To set up this model locally:
pip install -r requirements.txt
poetry_generation.ipynb to explore the complete implementationThe required packages include:
Potential enhancements for the model include:
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.