Usage HuggingFace Transformers for header generation task
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model = AutoModelForSeq2SeqLM.from_pretrained("AlekseyKulnevich/Pegasus-HeaderGeneration")
tokenizer = PegasusTokenizer.from_pretrained('google/pegasus-large')
input_text # your text
input_ = tokenizer.batch_encode_plus([input_text], max_length=1024, pad_to_max_length=True,
truncation=True, padding='longest', return_tensors='pt')
input_ids = input_['input_ids']
input_mask = input_['attention_mask']
headers = model.generate(input_ids=input_ids,
attention_mask=input_mask,
num_beams=32,
no_repeat_ngram_size=2,
early_stopping=True,
num_return_sequences=10)
headers = tokenizer.batch_decode(headers, skip_special_tokens=True)
Decoder configuration examples:
Input text you can see here
headers = model.generate(input_ids=input_ids,
attention_mask=input_mask,
num_beams=32,
no_repeat_ngram_size=2,
early_stopping=True,
num_return_sequences=20)
tokenizer.batch_decode(headers, skip_special_tokens=True)
output:
- the impact of climate change on tropical cyclones
- the impact of human induced climate change on tropical cyclones
- the impact of climate change on tropical cyclone formation in the midlatitudes
- how climate change will expand the range of tropical cyclones?
- the impact of climate change on tropical cyclones in the midlatitudes
- global warming will expand the range of tropical cyclones
- climate change will expand the range of tropical cyclones
- the impact of climate change on tropical cyclone formation
- the impact of human induced climate change on tropical cyclone formation
- tropical cyclones in the mid-latitudes
- climate change will expand the range of tropical cyclones in the middle latitudes
- global warming will expand the range of tropical cyclones, a new study says
- the impacts of climate change on tropical cyclones
- the impact of global warming on tropical cyclones
- climate change will expand the range of tropical cyclones, a new study says
- global warming will expand the range of tropical cyclones in the middle latitudes
- the effects of climate change on tropical cyclones
- how climate change will expand the range of tropical cyclones
- climate change will expand the range of tropical cyclones over the equator
- the impact of human induced climate change on tropical cyclones.
Also you can play with the following parameters in generate method:
-top_k
-top_p
Meaning of parameters to generate text you can see here