Colby/quotes
Viewer • Updated • 39.8k • 36
A character-level GPT model trained on Positive Quotes dataset.
This model is a character-level transformer based on the GPT architecture, trained on a collection of positive quotes. It uses multi-head self-attention with causal masking to generate text autoregressively.
This model is intended for educational purposes and text generation experimentation. It generates character-level text based on the patterns learned from the quotes dataset.
import torch
import json
# Load config
with open("config.json") as f:
config = json.load(f)
# Load vocab
with open("vocab.json") as f:
vocab = json.load(f)
stoi = vocab["stoi"]
itos = {int(k): v for k, v in vocab["itos"].items()}
decoder = lambda s: "".join([itos[c] for c in s])
encoder = lambda s: [stoi[c] for c in s]
# Rebuild model (use same class definitions from the training script)
model = gpt(config["vocab_size"])
model.load_state_dict(torch.load("model.pt"))
model.eval()
# Generate text
context = torch.zeros((1, 1), dtype=torch.long)
output = decoder(model.generate(context, max_new_token=500)[0].tolist())
print(output)
model.pt - Model state dictionaryconfig.json - Model hyperparametersconfig.yml - Hugging Face YAML metadatavocab.json - Character to index and index to character mappingsgenerated_output.txt - Sample generated textIf you use this model, please cite the dataset: Colby/quotes from Hugging Face Datasets.