GPT2-124 Fine-Tuned on Poetry with Reinforcement Learning (RL)
Model Description
This model, GPT2-124 Poetry RL, is a fine-tuned version of GPT-2 trained on the Gutenberg Poetry Corpus with Reinforcement Learning (RL). The model is optimized for poetic generation with enhanced stylistic qualities such as rhyme, coherence, and creativity.
Training Details
- Base Model: GPT-2 (124M)
- Dataset: Gutenberg Poetry Corpus
- Fine-Tuning Approach:
- Supervised fine-tuning on poetry lines.
- RL with custom reward functions:
- Rhyme Reward: Encourages rhyming lines.
- Coherence Reward: Ensures logical flow.
- Creativity Reward: Penalizes repetition and rewards unique wording.
How to Use
You can generate poetry using the transformers
library:
from transformers import GPT2LMHeadModel, GPT2Tokenizer
tokenizer = GPT2Tokenizer.from_pretrained("ayazfau/GPT2-124-poetry-RL")
model = GPT2LMHeadModel.from_pretrained("ayazfau/GPT2-124-poetry-RL")
def generate_poetry(prompt, max_length=50):
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
output = model.generate(input_ids, max_new_tokens=max_length, do_sample=True, top_k=50, top_p=0.95, pad_token_id=tokenizer.eos_token_id)
return tokenizer.decode(output[0], skip_special_tokens=True)
print(generate_poetry("fear kill dreams,"))
Model Performance
- The model generates rhyming and coherent poetic lines.
- Works well for short-form poetry and lyrical content.
- Still has some limitations in long-form poetry structure.
License
This model is released under the MIT License. Feel free to use it for research and creative writing!
Acknowledgments
- Trained using PyTorch Lightning and Hugging Face Transformers.
- Special thanks to the Gutenberg Poetry Corpus for providing high-quality literary data.
If you use this model, please consider citing it or leaving a star on Hugging Face! ⭐
- Downloads last month
- 18
Inference Providers
NEW
This model is not currently available via any of the supported Inference Providers.