skytnt/japanese-lyric
Updated • 33 • 4
How to use skytnt/gpt2-japanese-lyric-small with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="skytnt/gpt2-japanese-lyric-small") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("skytnt/gpt2-japanese-lyric-small")
model = AutoModelForCausalLM.from_pretrained("skytnt/gpt2-japanese-lyric-small")How to use skytnt/gpt2-japanese-lyric-small with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "skytnt/gpt2-japanese-lyric-small"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "skytnt/gpt2-japanese-lyric-small",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/skytnt/gpt2-japanese-lyric-small
How to use skytnt/gpt2-japanese-lyric-small with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "skytnt/gpt2-japanese-lyric-small" \
--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": "skytnt/gpt2-japanese-lyric-small",
"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 "skytnt/gpt2-japanese-lyric-small" \
--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": "skytnt/gpt2-japanese-lyric-small",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use skytnt/gpt2-japanese-lyric-small with Docker Model Runner:
docker model run hf.co/skytnt/gpt2-japanese-lyric-small
The model is used to generate Japanese lyrics.
You can try it on my website https://lyric.fab.moe/
import torch
from transformers import T5Tokenizer, GPT2LMHeadModel
tokenizer = T5Tokenizer.from_pretrained("skytnt/gpt2-japanese-lyric-small")
model = GPT2LMHeadModel.from_pretrained("skytnt/gpt2-japanese-lyric-small")
def gen_lyric(prompt_text: str):
prompt_text = "<s>" + prompt_text.replace("\n", "\\n ")
prompt_tokens = tokenizer.tokenize(prompt_text)
prompt_token_ids = tokenizer.convert_tokens_to_ids(prompt_tokens)
prompt_tensor = torch.LongTensor(prompt_token_ids).to(device)
prompt_tensor = prompt_tensor.view(1, -1)
# model forward
output_sequences = model.generate(
input_ids=prompt_tensor,
max_length=512,
top_p=0.95,
top_k=40,
temperature=1.0,
do_sample=True,
early_stopping=True,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
num_return_sequences=1
)
# convert model outputs to readable sentence
generated_sequence = output_sequences.tolist()[0]
generated_tokens = tokenizer.convert_ids_to_tokens(generated_sequence)
generated_text = tokenizer.convert_tokens_to_string(generated_tokens)
generated_text = "\n".join([s.strip() for s in generated_text.split('\\n')]).replace(' ', '\u3000').replace('<s>', '').replace('</s>', '\n\n---end---')
return generated_text
print(gen_lyric("桜が咲く"))
Training data contains 143,587 Japanese lyrics which are collected from uta-net by lyric_download