Downloads · 30 days
18
7% of all-time downloads
achavan1211/shakespeare-gpt
shakespeare-gpt is a text generation model from achavan1211. Use it when you need the model to write or continue text. It is set up for generic.
A small character-level GPT language model (~10.8M parameters) trained from scratch on the Tiny Shakespeare dataset following Andrej Karpathy's "Let's build GPT" tutorial.
Downloads · 30 days
18
7% of all-time downloads
All-time downloads
254
Public
Repo size
52.7 MB
Likes
0
Public
Click a slice to open those files.
.bin52.7 MB · 100%
From the Hugging Face model README
A small character-level GPT language model (~10.8M parameters) trained from scratch on the Tiny Shakespeare dataset following Andrej Karpathy's "Let's build GPT" tutorial.
This is a custom PyTorch model. See model.py for the architecture, config.json for hyperparameters, and vocab.json for the character-level tokenizer mappings.
import json, torch
from huggingface_hub import hf_hub_download
from model import GPTLanguageModel
config = json.load(open(hf_hub_download('achavan1211/shakespeare-gpt', 'config.json')))
vocab = json.load(open(hf_hub_download('achavan1211/shakespeare-gpt', 'vocab.json')))
stoi, itos = vocab['stoi'], {int(k): v for k, v in vocab['itos'].items()}
encode = lambda s: [stoi[c] for c in s]
decode = lambda l: ''.join(itos[i] for i in l)
model = GPTLanguageModel(**config)
model.load_state_dict(torch.load(hf_hub_download('achavan1211/shakespeare-gpt', 'pytorch_model.bin'), map_location='cpu'))
model.eval()
# Generate text
context = torch.zeros((1, 1), dtype=torch.long)
print(decode(model.generate(context, max_new_tokens=500)[0].tolist()))