Update README.md
Browse files
README.md
CHANGED
@@ -19,15 +19,25 @@ OUTPUT = ๊ฐ label์ ๋ง๋ ๋ด์ค ๊ธฐ์ฌ ์ ๋ชฉ์ ์์ฑํฉ๋๋ค.
|
|
19 |
```python
|
20 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
21 |
|
|
|
22 |
model_dir = "t5-large-korean-news-title-klue-ynat"
|
23 |
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
24 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_dir)
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
print(predicted_title)
|
32 |
```
|
33 |
|
|
|
19 |
```python
|
20 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
21 |
|
22 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
model_dir = "t5-large-korean-news-title-klue-ynat"
|
24 |
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
25 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_dir)
|
26 |
+
model.to(device)
|
27 |
|
28 |
+
label_list = ['IT๊ณผํ','๊ฒฝ์ ','์ฌํ','์ํ๋ฌธํ','์ธ๊ณ','์คํฌ์ธ ','์ ์น']
|
29 |
+
text = "IT๊ณผํ"
|
30 |
+
|
31 |
+
inputs = tokenizer.encode(text, max_length=256, truncation=True, return_tensors="pt")
|
32 |
+
with torch.no_grad():
|
33 |
+
output = model.generate(
|
34 |
+
input_ids,
|
35 |
+
do_sample=True, #์ํ๋ง ์ ๋ต ์ฌ์ฉ
|
36 |
+
max_length=128, # ์ต๋ ๋์ฝ๋ฉ ๊ธธ์ด๋ 50
|
37 |
+
top_k=50, # ํ๋ฅ ์์๊ฐ 50์ ๋ฐ์ธ ํ ํฐ์ ์ํ๋ง์์ ์ ์ธ
|
38 |
+
top_p=0.95, # ๋์ ํ๋ฅ ์ด 95%์ธ ํ๋ณด์งํฉ์์๋ง ์์ฑ
|
39 |
+
)
|
40 |
+
decoded_output = tokenizer.decode(output, skip_special_tokens=True)[0]
|
41 |
print(predicted_title)
|
42 |
```
|
43 |
|