Downloads · 30 days
28
11% of all-time downloads
achavan1211/shakespeare-gpt-bpe
shakespeare-gpt-bpe 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 decoder-only Transformer (~2.2M parameters) trained from scratch on the Tiny Shakespeare dataset. This is the BPE subword version: instead of a 65-character vocabulary, it trains a ~1000-token Byte-Pair Encodi…
Downloads · 30 days
28
11% of all-time downloads
All-time downloads
259
Public
Repo size
13.1 MB
Likes
0
Public
Click a slice to open those files.
.bin13.1 MB · 99%
From the Hugging Face model README
A small decoder-only Transformer (~2.2M parameters) trained from scratch on the Tiny Shakespeare dataset. This is the BPE subword version: instead of a 65-character vocabulary, it trains a ~1000-token Byte-Pair Encoding tokenizer on the corpus and trains the transformer over those subword tokens.
tokenizers)Custom PyTorch model. See model.py for the architecture, config.json for hyperparameters,
and tokenizer.json for the BPE tokenizer.
import json, torch
from tokenizers import Tokenizer
from huggingface_hub import hf_hub_download
from model import GPTLanguageModel
repo = "achavan1211/shakespeare-gpt-bpe"
config = json.load(open(hf_hub_download(repo, "config.json")))
tokenizer = Tokenizer.from_file(hf_hub_download(repo, "tokenizer.json"))
encode = lambda s: tokenizer.encode(s).ids
decode = lambda l: tokenizer.decode(l)
model_cfg = {k: v for k, v in config.items() if k != "tokenizer"}
model = GPTLanguageModel(**model_cfg)
model.load_state_dict(torch.load(hf_hub_download(repo, "pytorch_model.bin"), map_location="cpu"))
model.eval()
context = torch.zeros((1, 1), dtype=torch.long)
print(decode(model.generate(context, max_new_tokens=500)[0].tolist()))