Commit
·
2e5ce7b
1
Parent(s):
bad2adb
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
**Usage HuggingFace Transformers for header generation task**
|
2 |
+
```
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("AlekseyKulnevich/Pegasus-HeaderGeneration")
|
5 |
+
tokenizer = PegasusTokenizer.from_pretrained('google/pegasus-large')
|
6 |
+
input_text # your text
|
7 |
+
input_ = tokenizer.batch_encode_plus([input_text], max_length=1024, pad_to_max_length=True,
|
8 |
+
truncation=True, padding='longest', return_tensors='pt')
|
9 |
+
input_ids = input_['input_ids']
|
10 |
+
input_mask = input_['attention_mask']
|
11 |
+
headers = model.generate(input_ids=input_ids,
|
12 |
+
attention_mask=input_mask,
|
13 |
+
num_beams=32,
|
14 |
+
no_repeat_ngram_size=2,
|
15 |
+
early_stopping=True,
|
16 |
+
num_return_sequences=10)
|
17 |
+
headers = tokenizer.batch_decode(headers, skip_special_tokens=True)
|
18 |
+
```
|
19 |
+
**Decoder configuration examples:**
|
20 |
+
[**Input text you can see here**](https://www.bbc.com/news/science-environment-59775105)
|
21 |
+
```
|
22 |
+
headers = model.generate(input_ids=input_ids,
|
23 |
+
attention_mask=input_mask,
|
24 |
+
num_beams=32,
|
25 |
+
no_repeat_ngram_size=2,
|
26 |
+
early_stopping=True,
|
27 |
+
num_return_sequences=20)
|
28 |
+
tokenizer.batch_decode(headers, skip_special_tokens=True)
|
29 |
+
```
|
30 |
+
output:
|
31 |
+
1. *the impact of climate change on tropical cyclones*
|
32 |
+
2. *the impact of human induced climate change on tropical cyclones*
|
33 |
+
3. *the impact of climate change on tropical cyclone formation in the midlatitudes*
|
34 |
+
4. *how climate change will expand the range of tropical cyclones?*
|
35 |
+
5. *the impact of climate change on tropical cyclones in the midlatitudes*
|
36 |
+
6. *global warming will expand the range of tropical cyclones*
|
37 |
+
7. *climate change will expand the range of tropical cyclones*
|
38 |
+
8. *the impact of climate change on tropical cyclone formation*
|
39 |
+
9. *the impact of human induced climate change on tropical cyclone formation*
|
40 |
+
10. *tropical cyclones in the mid-latitudes*
|
41 |
+
11. *climate change will expand the range of tropical cyclones in the middle latitudes*
|
42 |
+
12. *global warming will expand the range of tropical cyclones, a new study says*
|
43 |
+
13. *the impacts of climate change on tropical cyclones*
|
44 |
+
14. *the impact of global warming on tropical cyclones*
|
45 |
+
15. *climate change will expand the range of tropical cyclones, a new study says*
|
46 |
+
16. *global warming will expand the range of tropical cyclones in the middle latitudes*
|
47 |
+
17. *the effects of climate change on tropical cyclones*
|
48 |
+
18. *how climate change will expand the range of tropical cyclones*
|
49 |
+
19. *climate change will expand the range of tropical cyclones over the equator*
|
50 |
+
20. *the impact of human induced climate change on tropical cyclones.*
|
51 |
+
Also you can play with the following parameters in generate method:
|
52 |
+
-top_k
|
53 |
+
-top_p
|
54 |
+
[**Meaning of parameters to generate text you can see here**](https://huggingface.co/blog/how-to-generate)
|