add: README.md
Browse files
README.md
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```python
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
+
|
5 |
+
# device setting
|
6 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
+
# load model and tokenizer
|
8 |
+
model_name_or_path = "ddobokki/gpt2_poem"
|
9 |
+
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name_or_path)
|
12 |
+
model.to(device)
|
13 |
+
|
14 |
+
keyword_start_token = "<k>"
|
15 |
+
keyword_end_token = "</k>"
|
16 |
+
text = "์ฐ ๊ผญ๋๊ธฐ๊ฐ ๋ณด์ด๋ ๊ฒฝ์น"
|
17 |
+
input_text = keyword_start_token + text + keyword_end_token
|
18 |
+
|
19 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
20 |
+
gen_ids = model.generate(
|
21 |
+
input_ids, max_length=64, num_beams=100, no_repeat_ngram_size=2
|
22 |
+
)
|
23 |
+
generated = tokenizer.decode(gen_ids[0, :].tolist(), skip_special_tokens=True)
|
24 |
+
>> ์ค๋ฅด๋ฝ๋ด๋ฆฌ๋ฝ
|
25 |
+
์ฐ ๊ผญ๋๊ธฐ๋ฅผ ์ฌ๋ ค๋ค๋ณด๋
|
26 |
+
์๋ํ ๋ฉ๊ณ ์๋ํ
|
27 |
+
๋๋ญ๊ฐ์ง์ ๋งค๋ฌ๋ฆฐ
|
28 |
+
์์ ์ฐ์ ํ ๋ง๋ฆฌ
|
29 |
+
์ด๋ฆ ๋ชจ๋ฅผ ํ ํํฌ๊ธฐ ์๊ณ
|
30 |
+
์ด๋๋ก ๊ฐ ํ์ฉ ๋ ๋๊ฐ ๋ฒ๋ ธ๋ค
|
31 |
+
```
|