Update README.md
Browse files
README.md
CHANGED
@@ -9,25 +9,26 @@ paust/pko-t5-base model based
|
|
9 |
|
10 |
Since this model is based on paust/pko-t5-base tokenizer, you need to import it.
|
11 |
|
12 |
-
from transformers import T5TokenizerFast, T5ForConditionalGeneration
|
13 |
tokenizer = T5TokenizerFast.from_pretrained("paust/pko-t5-base")
|
14 |
-
model = T5ForConditionalGeneration.from_pretrained(emotionanalysis/diaryempathizer-t5-ko)
|
15 |
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True, padding="max_length")
|
29 |
-
inputs = {key: value.to(device) for key, value in inputs.items()}
|
30 |
-
outputs = model.generate(input_ids=inputs["input_ids"], max_length=128, num_beams=4, early_stopping=True)
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
Since this model is based on paust/pko-t5-base tokenizer, you need to import it.
|
11 |
|
12 |
+
```from transformers import T5TokenizerFast, T5ForConditionalGeneration
|
13 |
tokenizer = T5TokenizerFast.from_pretrained("paust/pko-t5-base")
|
14 |
+
model = T5ForConditionalGeneration.from_pretrained(emotionanalysis/diaryempathizer-t5-ko)```
|
15 |
|
16 |
+
Test code
|
17 |
|
18 |
+
```import torch
|
19 |
+
from transformers import T5TokenizerFast, T5ForConditionalGeneration
|
20 |
|
21 |
+
model = T5ForConditionalGeneration.from_pretrained(emotionanalysis/diaryempathizer-t5-ko)
|
22 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
+
model.to(device)
|
24 |
+
|
25 |
+
tokenizer = T5TokenizerFast.from_pretrained("paust/pko-t5-base")
|
26 |
+
input_text = """
|
27 |
+
"""
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True, padding="max_length")
|
30 |
+
inputs = {key: value.to(device) for key, value in inputs.items()}
|
31 |
+
outputs = model.generate(input_ids=inputs["input_ids"], max_length=128, num_beams=4, early_stopping=True)
|
32 |
+
|
33 |
+
generated_comment = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
34 |
+
print(generated_comment)```
|