Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,68 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: mit
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: ja
|
3 |
+
tags:
|
4 |
+
- ja
|
5 |
+
- japanese
|
6 |
+
- gpt2
|
7 |
+
- text-generation
|
8 |
+
- lm
|
9 |
+
- nlp
|
10 |
license: mit
|
11 |
+
widget:
|
12 |
+
- text: "未来に揺れる花 過去にもあった花"
|
13 |
---
|
14 |
+
|
15 |
+
# Japanese GPT2 Lyric Model
|
16 |
+
|
17 |
+
## Model description
|
18 |
+
|
19 |
+
The model is used to generate Japanese lyrics.
|
20 |
+
|
21 |
+
## How to use
|
22 |
+
|
23 |
+
```python
|
24 |
+
import torch
|
25 |
+
from transformers import T5Tokenizer, GPT2LMHeadModel, TextGenerationPipeline
|
26 |
+
|
27 |
+
tokenizer = T5Tokenizer.from_pretrained("skytnt/gpt2-japanese-lyric-small")
|
28 |
+
model = GPT2LMHeadModel.from_pretrained("skytnt/gpt2-japanese-lyric-small")
|
29 |
+
|
30 |
+
|
31 |
+
def gen_lyric(prompt_text: str):
|
32 |
+
prompt_text = prompt_text.replace("\n", "[SEP]")
|
33 |
+
prompt_tokens = tokenizer.tokenize(prompt_text)
|
34 |
+
prompt_token_ids = tokenizer.convert_tokens_to_ids(prompt_tokens)
|
35 |
+
prompt_tensor = torch.LongTensor(prompt_token_ids)
|
36 |
+
prompt_tensor = prompt_tensor.view(1, -1)
|
37 |
+
# model forward
|
38 |
+
output_sequences = model.generate(
|
39 |
+
input_ids=prompt_tensor,
|
40 |
+
max_length=512,
|
41 |
+
top_p=0.95,
|
42 |
+
top_k=40,
|
43 |
+
temperature=1.0,
|
44 |
+
do_sample=True,
|
45 |
+
early_stopping=True,
|
46 |
+
bos_token_id=tokenizer.bos_token_id,
|
47 |
+
eos_token_id=tokenizer.eos_token_id,
|
48 |
+
pad_token_id=tokenizer.pad_token_id,
|
49 |
+
num_return_sequences=1
|
50 |
+
)
|
51 |
+
|
52 |
+
# convert model outputs to readable sentence
|
53 |
+
generated_sequence = output_sequences.tolist()[0]
|
54 |
+
generated_tokens = tokenizer.convert_ids_to_tokens(generated_sequence)
|
55 |
+
generated_text = tokenizer.convert_tokens_to_string(generated_tokens)
|
56 |
+
generated_text = "\n".join([s.strip() for s in generated_text.split('[SEP]')]).replace(' ', '\u3000').replace(
|
57 |
+
'</s>', '\n\n---end---')
|
58 |
+
return generated_text
|
59 |
+
|
60 |
+
|
61 |
+
print(gen_lyric("未来に揺れる花 過去にもあった花"))
|
62 |
+
|
63 |
+
```
|
64 |
+
|
65 |
+
## Training data
|
66 |
+
|
67 |
+
Training data ([click to download](https://data.anyweb.xyz/dataset/lyric.zip)) contains 48,394 Japanese lyrics which are collected from [NetEasyMusic](https://music.163.com/) by [lyric_download](https://github.com/SkyTNT/lyric_downlowd)
|
68 |
+
|