biglam/gutenberg-poetry-corpus
Viewer • Updated • 3.09M • 1.05k • 20
How to use ayazfau/GPT2-124M-poetry-RL with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="ayazfau/GPT2-124M-poetry-RL") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("ayazfau/GPT2-124M-poetry-RL")
model = AutoModelForCausalLM.from_pretrained("ayazfau/GPT2-124M-poetry-RL")How to use ayazfau/GPT2-124M-poetry-RL with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "ayazfau/GPT2-124M-poetry-RL"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ayazfau/GPT2-124M-poetry-RL",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/ayazfau/GPT2-124M-poetry-RL
How to use ayazfau/GPT2-124M-poetry-RL with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "ayazfau/GPT2-124M-poetry-RL" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ayazfau/GPT2-124M-poetry-RL",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "ayazfau/GPT2-124M-poetry-RL" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ayazfau/GPT2-124M-poetry-RL",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use ayazfau/GPT2-124M-poetry-RL with Docker Model Runner:
docker model run hf.co/ayazfau/GPT2-124M-poetry-RL
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.
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,"))
This model is released under the MIT License. Feel free to use it for research and creative writing!
If you use this model, please consider citing it or leaving a star on Hugging Face! ⭐