ddobokki commited on
Commit
6ee6039
โ€ข
1 Parent(s): 87a38e1

add: README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -0
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
+ ```