PULI-GPT-2 Petőfi (Fine-Tuned Hungarian Poetry Generator)
I fine-tuned NYTK/PULI-GPT-2 on Petőfi's literature to generate poems in his style. I made it for my own enjoyment to experiment, I think you can have a good time with it. It's far from perfect, but you get suprisingly good results from time to time.
Model Details
- Base Model: NYTK/PULI-GPT-2 (~345M parameters)
- Language: Hungarian
- Fine-tuned on: Petőfi Sándor poems
Quickstart
Usage with transformers library:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "SzaBotond/puli-gpt2-petofi-v01"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
prompt = "A pusztán fúj a szél,"
inputs = tokenizer(prompt, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=120,
temperature=0.85,
top_k=50,
top_p=0.9,
repetition_penalty=1.15,
no_repeat_ngram_size=3,
pad_token_id=tokenizer.eos_token_id
)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)
Training Hyperparameters
Made in pytorch.
| Parameter | Value |
|---|---|
| Epochs | 5 (early stopping) |
| Batch size | 2 |
| Grad accum | 4 (effective batch size = 8) |
| Learning rate | 3e-5 |
| Weight decay | 0.01 |
| Max seq len | 256 token |
| Optimalization | FP16 mixed precision + Gradient Checkpointing |
I trained it locally so my hardware capacity was pretty limiting in the process.
Reference
@inproceedings {yang-puli,
title = {Jönnek a nagyok! BERT-Large, GPT-2 és GPT-3 nyelvmodellek magyar nyelvre},
booktitle = {XIX. Magyar Számítógépes Nyelvészeti Konferencia (MSZNY 2023)},
year = {2023},
publisher = {Szegedi Tudományegyetem, Informatikai Intézet},
address = {Szeged, Hungary},
author = {Yang, Zijian Győző and Dodé, Réka and Ferenczi, Gergő and Héja, Enikő and Jelencsik-Mátyus, Kinga and Kőrös, Ádám and Laki, László János and Ligeti-Nagy, Noémi and Vadász, Noémi and Váradi, Tamás},
pages = {247--262}
}
//I don't know if this is correct way of citing in this situation, but I tried//
- Downloads last month
- 277
Model tree for SzaBotond/puli-gpt2-petofi-v01
Base model
NYTK/PULI-GPT-2