Downloads · 30 days
36
6% of all-time downloads
Aananda-giri/GPT2-Nepali
GPT2-Nepali is a text generation model from Aananda-giri. Use it when you need the model to write or continue text.
Welcome to the GPT2-Nepali repository! This project features a GPT-2 model trained from scratch on a 12GB Nepali text dataset derived from the NepBERTa project. The model is specifically tailored for the Nepali langua…
Downloads · 30 days
36
6% of all-time downloads
All-time downloads
639
Public
Parameters
165M
8 GB on disk
Likes
1
Public
Click a slice to open those files.
.pth4 GB · 86%
From the Hugging Face model README
Welcome to the GPT2-Nepali repository! This project features a GPT-2 model trained from scratch on a 12GB Nepali text dataset derived from the NepBERTa project. The model is specifically tailored for the Nepali language and includes a user-friendly chat interface hosted on Hugging Face Spaces.
Chat Interface:
Hugging-Face-Space
Training Code:
GitHub Repository
Dataset:
12GB Nepali text extracted from the NepBERTa project
GPT2-Nepali adapts the GPT-2 model training process (inspired by the resource Build a Large Language Model (From Scratch)) to address the nuances of the Nepali language. Key modifications include the development of a dedicated BPE tokenizer for Nepali and adjustments to the dataloader to better handle pre-tokenized datasets.
git clone https://github.com/Aananda-giri/GPT2-Nepali.git
cd GPT2-Nepali
pip install -r requirements.txt
gpt_model_code.pyimport requests
res=requests.get(r"https://raw.githubusercontent.com/Aananda-giri/GPT2-Nepali/main/3.%20GPT2-Nepali/2_inference/gpt_model_code.py")
with open('gpt_model_code.py','w') as f:
f.write(res.text)
Below is a sample script to load the model and generate text:
from transformers import PreTrainedTokenizerFast
import torch
from gpt_model_code import GPTModel, GPT_CONFIG_124M, generate # Use model_code if applicable
# Determine the device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Initialize and load the model
model = GPTModel(GPT_CONFIG_124M)
model.to(device)
# Load the pre-trained model from Hugging Face
model = GPTModel.from_pretrained("Aananda-giri/GPT2-Nepali")
model.to(device)
# Load the tokenizer
tokenizer = PreTrainedTokenizerFast.from_pretrained("Aananda-giri/GPT2-Nepali")
# Generate sample text
prompt = "रामले भात"
generated_text = generate(
model,
prompt,
tokenizer,
max_new_tokens=100,
temperature=0.7,
top_k=50,
top_p=None, # Use nucleus sampling if needed
eos_id=None,
repetition_penalty=1.2,
penalize_len_below=50
)
print(generated_text)
A special thank you to @rasbt for the inspiration and for authoring Build a Large Language Model (From Scratch)—one of the best resources on LLMs available!
Happy-Coding!