Downloads · 30 days
17
8% of all-time downloads
snskrt/Sanskrit-Qwen2.5-7B-base
Sanskrit-Qwen2.5-7B-base is a text generation model from snskrt. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Note: This project represents a series of experimental attempts to create specialized Sanskrit language models. While significant effort was invested, the results did not meet the quality standards required for practi…
Downloads · 30 days
17
8% of all-time downloads
All-time downloads
211
Public
Parameters
7.6B
15.2 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors15.2 GB · 100%
From the Hugging Face model README
Note: This project represents a series of experimental attempts to create specialized Sanskrit language models. While significant effort was invested, the results did not meet the quality standards required for practical use. This repository is maintained for research documentation and learning purposes.
This model is a fine-tuned version of Qwen/Qwen2.5-7B specialized for Sanskrit language modeling and text generation. The model has been trained on a comprehensive dataset of 664,104+ clean Sanskrit texts from classical literature, enhanced with Sanskrit-specific punctuation tokens and optimized for coherent Sanskrit text generation.
This is a specialized Sanskrit language model built on the Qwen2.5-7B architecture, designed specifically for Sanskrit text generation, completion, and understanding tasks.
Key Features:
Capabilities:
Enhanced Tokenizer:
Dataset: diabolic6045/Sanskrit-shlok-collection
Data Processing:
Source Distribution:
| Source | Texts | Percentage |
|---|---|---|
| Bhagavata Purana | 125,432 | 18.9% |
| Mahabharata | 98,765 | 14.9% |
| Ramayana | 87,234 | 13.1% |
| Upanishads | 76,543 | 11.5% |
| Vedas | 65,432 | 9.9% |
| Other Sources | 210,698 | 31.7% |
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load model and tokenizer
model_name = "snskrt/Sanskrit-Qwen2.5-7B-base"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True
)
# Text generation function
def generate_sanskrit_text(prompt, max_length=256, temperature=0.7):
"""
Generate Sanskrit text from a given prompt
Args:
prompt (str): Sanskrit text prompt
max_length (int): Maximum length of generated text
temperature (float): Sampling temperature (0.1-1.0)
Returns:
str: Generated Sanskrit text
"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=max_length,
temperature=temperature,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id
)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return generated_text[len(prompt):].strip()
# Example usage
prompt = "नमस्ते संस्कृत भाषा ।"
generated = generate_sanskrit_text(prompt, max_length=128)
print(f"Prompt: {prompt}")
print(f"Generated: {generated}")
def complete_sanskrit_text(partial_text, completion_length=100):
"""
Complete a partial Sanskrit text
Args:
partial_text (str): Partial Sanskrit text to complete
completion_length (int): Length of completion
Returns:
str: Completed Sanskrit text
"""
return generate_sanskrit_text(partial_text, max_length=completion_length, temperature=0.8)
# Example usage
partial_verse = "गीतां सुगीतां कर्तव्यां"
completed = complete_sanskrit_text(partial_verse)
print(f"Partial: {partial_verse}")
print(f"Completed: {completed}")
def generate_sanskrit_verse(theme="", style="classical"):
"""
Generate a Sanskrit verse on a given theme
Args:
theme (str): Theme for the verse
style (str): Style of verse (classical, modern, etc.)
Returns:
str: Generated Sanskrit verse
"""
if theme:
prompt = f"एकं {theme} विषये संस्कृत श्लोकं रचयतु ।"
else:
prompt = "एकं संस्कृत श्लोकं रचयतु ।"
return generate_sanskrit_text(prompt, max_length=200, temperature=0.9)
# Example usage
verse = generate_sanskrit_verse("धर्मः", "classical")
print(f"Generated Verse: {verse}")
def batch_generate_sanskrit(prompts, max_length=128):
"""
Generate Sanskrit text for multiple prompts
Args:
prompts (list): List of Sanskrit prompts
max_length (int): Maximum length per generation
Returns:
list: List of generated texts
"""
results = []
for prompt in prompts:
generated = generate_sanskrit_text(prompt, max_length)
results.append(generated)
return results
# Example usage
prompts = [
"संस्कृत भाषा",
"धर्मः सत्यं",
"विद्या ददाति"
]
generated_texts = batch_generate_sanskrit(prompts)
for prompt, generated in zip(prompts, generated_texts):
print(f"Prompt: {prompt} → Generated: {generated}")
Model Configuration:
LoRA Configuration:
Training Parameters:
Precision and Memory:
Training Metrics:
Convergence:
This model was trained using: <br> <img src="https://raw.githubusercontent.com/axolotl-ai-cloud/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>
<details><summary>See axolotl config</summary>axolotl version: 0.12.2
# Base model configuration
base_model: Qwen/Qwen2.5-7B
trust_remote_code: true
# Custom Sanskrit tokenizer configuration
tokenizer_config: sanskrit_tokenizer
tokenizer_type: AutoTokenizer
tokenizer_use_fast: true
tokenizer_legacy: false
tokenizer_save_jinja_files: true
# Resize embeddings for new tokens if needed
resize_token_embeddings_to_32x: true
mean_resizing_embeddings: false
shrink_embeddings: false
# Dataset configuration for text completion
datasets:
- path: sanskrit_clean_dataset.jsonl
type: completion
field: text
# Dataset preparation
dataset_prepared_path:
val_set_size: 0.1
output_dir: ./outputs/sanskrt-qwen-lora
# Sequence configuration
sequence_len: 1024
sample_packing: true
eval_sample_packing: true
# LoRA configuration
adapter: lora
lora_r: 32
lora_alpha: 64
lora_dropout: 0.05
lora_target_linear: true
lora_target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
gradient_accumulation_steps: 2
micro_batch_size: 2
num_epochs: 3
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
learning_rate: 0.0003
# Precision configuration
bf16: auto
tf32: true
# Memory optimization
gradient_checkpointing: true
gradient_checkpointing_kwargs:
use_reentrant: false
flash_attention: true
# Training schedule
warmup_ratio: 0.1
evals_per_epoch: 4
saves_per_epoch: 1
weight_decay: 0.0
hub_model_id: snskrt/Sanskrit-Qwen2.5-7B-base-lora
</details><br>
। (danda - Sanskrit period) - ID: 151665॥ (double danda - Sanskrit verse end) - ID: 151666If you use this model in your research, please cite:
@misc{sanskrit-qwen2.5-7b-base,
title={Sanskrit Qwen2.5-7B Base Model: A Specialized Language Model for Sanskrit Text Generation},
author={[Your Name]},
year={2024},
url={https://huggingface.co/snskrt/Sanskrit-Qwen2.5-7B-base}
}
This model is released under the Apache 2.0 License. See the LICENSE file for more details.