Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
pipeline_tag: text2text-generation
|
| 5 |
+
tags:
|
| 6 |
+
- t5
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
```python
|
| 10 |
+
from transformers import T5ForConditionalGeneration
|
| 11 |
+
from transformers import T5TokenizerFast as T5Tokenizer
|
| 12 |
+
model = "svjack/summary-dialogue-eng"
|
| 13 |
+
device = "cpu"
|
| 14 |
+
tokenizer = T5Tokenizer.from_pretrained(model)
|
| 15 |
+
model = T5ForConditionalGeneration.from_pretrained(model).to(device).eval()
|
| 16 |
+
|
| 17 |
+
prompt = "The Wisconsin Territorial Centennial half dollar was designed by David Parsons and Benjamin Hawkins and minted by the United States Bureau of the Mint in 1936. The obverse (pictured) depicts a pick axe and lead ore, referring to the lead mining in early Wisconsin"
|
| 18 |
+
prompt = "{}\nCandidates:Tom Jack".format(prompt)
|
| 19 |
+
|
| 20 |
+
encode = tokenizer(prompt, return_tensors='pt').to(device)
|
| 21 |
+
answer = model.generate(encode.input_ids,
|
| 22 |
+
max_length = 128,
|
| 23 |
+
num_beams=2,
|
| 24 |
+
top_p = 0.95,
|
| 25 |
+
top_k = 50,
|
| 26 |
+
repetition_penalty = 2.5,
|
| 27 |
+
length_penalty=1.0,
|
| 28 |
+
early_stopping=True,
|
| 29 |
+
)[0]
|
| 30 |
+
decoded = tokenizer.decode(answer, skip_special_tokens=True)
|
| 31 |
+
decoded.replace("Tom:", "\n").replace("Jack:", "\n").split("\n")
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
</br>
|
| 35 |
+
|
| 36 |
+
```json
|
| 37 |
+
['',
|
| 38 |
+
' Have you seen the Wisconsin Territorial Centennial half dollar? ',
|
| 39 |
+
' Yeah, it was designed by David Parsons and Benjamin Hawkins. ',
|
| 40 |
+
' What is it? ',
|
| 41 |
+
" It's a half dollar with a pick axe and lead ore. ",
|
| 42 |
+
" That's great!"]
|
| 43 |
+
```
|