Update README.md
Browse files
README.md
CHANGED
@@ -43,4 +43,25 @@ Used the _example/seq2seq/run_summarization.py_ script from the transformers sou
|
|
43 |
eval_rouge2: 23.6137,\
|
44 |
eval_rougeL: 37.2397,\
|
45 |
eval_rougeLsum: 42.7126,\
|
46 |
-
eval_samples_per_second: 4.302
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
eval_rouge2: 23.6137,\
|
44 |
eval_rougeL: 37.2397,\
|
45 |
eval_rougeLsum: 42.7126,\
|
46 |
+
eval_samples_per_second: 4.302
|
47 |
+
|
48 |
+
## Example
|
49 |
+
|
50 |
+
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
|
51 |
+
|
52 |
+
model_name = "jpcorb20/pegasus-large-reddit_tifu-samsum-256"
|
53 |
+
|
54 |
+
tokenizer = PegasusTokenizer.from_pretrained(model_name)
|
55 |
+
model = PegasusForConditionalGeneration.from_pretrained(model_name)
|
56 |
+
|
57 |
+
src_text = """Carter: Hey Alexis, I just wanted to let you know that I had a really nice time with you tonight.\r\nAlexis: Thanks Carter. Yeah, I really enjoyed myself as well.\r\nCarter: If you are up for it, I would really like to see you again soon.\r\nAlexis: Thanks Carter, I'm flattered. But I have a really busy week coming up.\r\nCarter: Yeah, no worries. I totally understand. But if you ever want to go grab dinner again, just let me know.\r\nAlexis: Yeah of course. Thanks again for tonight. Carter: Sure. Have a great night.\r\n"""
|
58 |
+
|
59 |
+
token_params = dict(max_length=256, truncation=True, padding='longest', return_tensors="pt")
|
60 |
+
batch = tokenizer(src_text, **token_params)
|
61 |
+
|
62 |
+
translated = model.generate(**batch)
|
63 |
+
|
64 |
+
decode_params = dict(num_beams=5, min_length=16, max_length=128, length_penalty=2)
|
65 |
+
tgt_text = tokenizer.batch_decode(translated, skip_special_tokens=True, **decode_params)
|
66 |
+
|
67 |
+
print(tgt_text)
|