Downloads · 30 days
8
13% of all-time downloads
kriteekathapa/lstm-poem-generator
lstm-poem-generator is a text generation model from kriteekathapa. Use it when you need the model to write or continue text. The card lists the license as mit.
A character-level UNILSTM model fine-tuned for poetry generation.
Downloads · 30 days
8
13% of all-time downloads
All-time downloads
61
Public
Repo size
70.7 MB
Likes
0
Public
Click a slice to open those files.
.pt70.7 MB · 100%
From the Hugging Face model README
A character-level UNILSTM model fine-tuned for poetry generation.
This is a custom PyTorch LSTM model trained on a poetry dataset for generating poems.
import torch
from model import BiLSTMPoetryModel # or UnidirectionalLSTMPoetryModel
from shared.preprocess import CharVocabulary
# Load vocabulary
vocab = CharVocabulary.load("vocab.json")
# Load model
model = BiLSTMPoetryModel(
vocab_size=vocab.vocab_size,
embedding_dim=256,
hidden_dim=512,
num_layers=3,
dropout=0.0, # No dropout for inference
pad_idx=vocab.pad_idx
)
checkpoint = torch.load("best_model.pt", map_location="cpu")
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
# Generate a poem
prompt = "Title: The Moon\n\n"
start_tokens = vocab.encode(prompt, add_special_tokens=False)
generated = model.generate(start_tokens, vocab, max_length=300, device="cpu")
print(generated)
best_model.pt: PyTorch model checkpointvocab.json: Character vocabulary mappingconfig.json: Training configurationMIT License