Downloads · 30 days
170
45% of all-time downloads
Prahaladha/telugu-diffusion-lm
telugu-diffusion-lm is a text generation model from Prahaladha. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
<div align="center" <img src="https://img.shields.io/badge/Language-Telugu-blue" alt="Telugu"/ <img src="https://img.shields.io/badge/Model-Diffusion%20LM-green" alt="Diffusion LM"/ <img src="https://img.shields.io/ba…
Downloads · 30 days
170
45% of all-time downloads
All-time downloads
377
Public
Parameters
278M
2.2 GB on disk
Likes
3
Public
Click a slice to open those files.
.safetensors1.1 GB · 99%
From the Hugging Face model README
The first diffusion-based language model for Telugu! This model explores masked diffusion language modeling for Telugu text generation, adapting the MDLM (Masked Diffusion Language Models) architecture for an Indic language.
Unlike traditional autoregressive models (GPT-style), this model generates text through iterative denoising, starting from completely masked sequences and progressively revealing tokens.
| Attribute | Value |
|---|---|
| Architecture | Masked Diffusion Language Model (MDLM) |
| Base Model | IndicBERTv2-MLM-only |
| Parameters | ~110M |
| Max Context | 1024 tokens (extended from 512) |
| Training Data | IndicVault Telugu Q&A (93K pairs) |
| Languages | Telugu (primary), English (limited) |
| Task | Conditional text generation (Q&A) |
Phase 1: Pretraining (Completed)
Phase 2: SFT (Current)
<BOS>, <EOS>, <START_ID>, <END_ID>, <EOT_ID>Key Innovation: Query mask padding with 1s (instead of 0s) so the model learns to predict EOS tokens after answers, preventing repetitive generation.
pip install torch transformers safetensors streamlit
import torch
from transformers import AutoModelForMaskedLM, AutoTokenizer
from safetensors.torch import load_file
# Load model and tokenizer
model_name = "Prahaladha/telugu-diffusion-lm"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForMaskedLM.from_pretrained(model_name)
model.eval()
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
# Prepare input
question = "హెల్త్ కేర్ ఎక్స్పెన్సెస్ ని నా పర్సనల్ బడ్జెట్ లో ఎలా ఇంక్లూడ్ చేసుకోవాలి?"
chat = [{"role": "user", "content": question}]
# Apply chat template
result = tokenizer.apply_chat_template(
chat,
tokenize=True,
add_generation_prompt=True,
)
prompt_ids = result if isinstance(result, list) else result["input_ids"]
# Prepare masked sequence
seq_len = 128
prompt_len = len(prompt_ids)
x = torch.full((1, seq_len), tokenizer.mask_token_id, dtype=torch.long, device=device)
x[0, :prompt_len] = torch.tensor(prompt_ids, device=device)
mask = torch.ones((1, seq_len), dtype=torch.bool, device=device)
mask[0, :prompt_len] = False
attn_mask = torch.ones((1, seq_len), dtype=torch.long, device=device)
# Diffusion generation
num_steps = 64
temperature = 0.7
times = torch.linspace(1.0, 0.0, num_steps + 1, device=device)
for t, s in zip(times[:-1], times[1:]):
with torch.no_grad():
logits = model(input_ids=x, attention_mask=attn_mask).logits
# Sample masked positions
if mask.any():
masked_logits = logits[mask] / temperature
probs = torch.softmax(masked_logits, dim=-1)
sampled = torch.multinomial(probs, num_samples=1).squeeze(-1)
x[mask] = sampled
# Remask (random strategy)
if s > 0:
mask = mask & (torch.rand_like(mask, dtype=torch.float) < s / t)
x[mask] = tokenizer.mask_token_id
# Decode answer
answer_ids = x[0, prompt_len:].tolist()
answer_tokens = [tid for tid in answer_ids
if tid not in [tokenizer.mask_token_id, tokenizer.pad_token_id, tokenizer.eos_token_id]]
answer = tokenizer.decode(answer_tokens, skip_special_tokens=True)
print(f"Q: {question}")
print(f"A: {answer}")
A full interactive demo is available in the repository:
streamlit run streamlit_app.py
| Aspect | This Model (Diffusion) | Autoregressive (GPT-style) |
|---|---|---|
| Generation | Bidirectional, iterative | Left-to-right, sequential |
| Speed | Slower (64+ steps) | Faster (1 step per token) |
| Context | Full sequence | Previous tokens only |
| Training | Complex (diffusion objective) | Simpler (next-token prediction) |
| Telugu Performance | Experimental | More mature |
# SFT Phase
base_model: ai4bharat/IndicBERTv2-MLM-only
max_length: 1024
batch_size: 32
learning_rate: 5e-5
warmup_steps: 500
training_samples: ~50000
validation_loss: 2.60
optimizer: AdamW
scheduler: linear with warmup
If you use this model in your research, please cite:
The base model and framework:
@inproceedings{kakwani2020indicnlpsuite,
title={{IndicNLPSuite: Monolingual Corpora, Evaluation Benchmarks and Pre-trained Multilingual Language Models for Indian Languages}},
author={Divyanshu Kakwani and Anoop Kunchukuttan and Satish Golla and Gokul N.C. and Avik Bhattacharyya and Mitesh M. Khapra and Pratyush Kumar},
year={2020},
booktitle={Findings of EMNLP},
}
@article{sahoo2024simple,
title={Simple and Effective Masked Diffusion Language Models},
author={Sahoo, Subham Sekhar and Arriola, Marianne and Schiff, Yair and Gokaslan, Aaron and Marroquin, Edgar and Chiang, Justin T and Voleti, Vikash and Galashov, Alexandre and Li, Cheng-Ping and Rish, Irina and others},
journal={arXiv preprint arXiv:2406.07524},
year={2024}
}
This is a research project. Contributions, suggestions, and feedback are welcome!
Issues we're working on: