Text Generation
Transformers
PyTorch
Russian
gpt2
keywords2poetry
Pushkin
Mayakovsky
Esenin
Blok
Tyutchev
text-generation-inference
Instructions to use AnyaSchen/rugpt3-medium-key2poetry with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AnyaSchen/rugpt3-medium-key2poetry with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AnyaSchen/rugpt3-medium-key2poetry")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("AnyaSchen/rugpt3-medium-key2poetry") model = AutoModelForCausalLM.from_pretrained("AnyaSchen/rugpt3-medium-key2poetry") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use AnyaSchen/rugpt3-medium-key2poetry with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AnyaSchen/rugpt3-medium-key2poetry" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AnyaSchen/rugpt3-medium-key2poetry", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AnyaSchen/rugpt3-medium-key2poetry
- SGLang
How to use AnyaSchen/rugpt3-medium-key2poetry with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "AnyaSchen/rugpt3-medium-key2poetry" \ --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": "AnyaSchen/rugpt3-medium-key2poetry", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
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 "AnyaSchen/rugpt3-medium-key2poetry" \ --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": "AnyaSchen/rugpt3-medium-key2poetry", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AnyaSchen/rugpt3-medium-key2poetry with Docker Model Runner:
docker model run hf.co/AnyaSchen/rugpt3-medium-key2poetry
This repo contains the fune-tuned version of ai-forever/rugpt3medium_based_on_gpt2, which can generate poetry from keywords in style of Pushkin, Mayakovsky, Esenin, Blok and Tyutchev.
To use this model, you can do this:
from transformers import AutoTokenizer, AutoModelForCausalLM
def generate_poetry(input: str, model, num_beams=3):
input = input if len(input) > 0 else tokenizer.bos_token
input_ids = tokenizer.encode(input, return_tensors="pt").to(device)
# Create an attention mask
attention_mask = (input_ids != tokenizer.pad_token_id).float()
# Set the pad_token_id
tokenizer.pad_token_id = tokenizer.eos_token_id
with torch.no_grad():
out = model.generate(input_ids,
do_sample=True,
num_beams=num_beams,
temperature=2.0,
top_p=0.9,
max_length = 200,
eos_token_id=tokenizer.eos_token_id,
bos_token_id=tokenizer.bos_token_id,
attention_mask=attention_mask
).to(device)
return tokenizer.batch_decode(out, skip_special_tokens=True)[0]
path = 'AnyaSchen/rugpt3-medium-keywords2poetry'
tokenizer = AutoTokenizer.from_pretrained(path)
model = AutoModelForCausalLM.from_pretrained(path).to(device)
inp = 'Автор: Маяковский\nКлючевые слова:<write your keywords>'
print(generate_poetry(inp, model))
- Downloads last month
- 4