Downloads · 30 days
0
Kowshik24/BanglaLM
BanglaLM is a text generation model from Kowshik24. Use it when you need the model to write or continue text. The card lists the license as apache-2.0.
This repository contains a simple Bigram Language Model implemented in PyTorch. The model is trained to predict the next character in a sequence, given the current character. It's a character-level model and can be us…
Downloads · 30 days
0
Access
Public
Updated Feb 7, 2024
Repo size
1 MB
Likes
0
Public
Click a slice to open those files.
.pth1 MB · 99%
From the Hugging Face model README
This repository contains a simple Bigram Language Model implemented in PyTorch. The model is trained to predict the next character in a sequence, given the current character. It's a character-level model and can be used for tasks like text generation.
First, clone this repository:
To load the model, you need to initialize it with the vocabulary size and load the pre-trained weights:
import torch
from model import BigramLanguageModel
vocab_size = 225
model = BigramLanguageModel(vocab_size)
model.load_state_dict(torch.load('path_to_your_model.pth', map_location=torch.device('cpu')))
model.eval()
import json
with open('tokenizer_mappings.json', 'r', encoding='utf-8') as f:
mappings = json.load(f)
stoi = mappings['stoi']
itos = mappings['itos']
# Example usage
encode = lambda s: [stoi[c] for c in s]
decode = lambda l: ''.join([itos[i] for i in l])
context = torch.tensor([encode("Your initial text")], dtype=torch.long)
generated_text_indices = model.generate(context, max_new_tokens=100)
print(decode(generated_text_indices[0].tolist()))