Usage HuggingFace Transformers for question generation task
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model = AutoModelForSeq2SeqLM.from_pretrained("AlekseyKulnevich/Pegasus-QuestionGeneration")
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']
questions = 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)
questions = tokenizer.batch_decode(questions, skip_special_tokens=True)
Decoder configuration examples:
questions = 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)
tokenizer.batch_decode(questions, skip_special_tokens=True)
output:
- What is the impact of human induced climate change on tropical cyclones?
- What is the impact of climate change on tropical cyclones?
- What is the impact of human induced climate change on tropical cyclone formation?
- How many tropical cyclones will occur in the mid-latitudes?
- What is the impact of climate change on the formation of tropical cyclones?
- Is it possible for a tropical cyclone to form in the middle latitudes?
- How many tropical cyclones will be formed in the mid-latitudes?
- How many tropical cyclones will there be in the mid-latitudes?
- How many tropical cyclones will form in the mid-latitudes?
- What is the impact of global warming on tropical cyclones?
- How long does it take for a tropical cyclone to form?
- 'What are the impacts of climate change on tropical cyclones?*
- What are the effects of climate change on tropical cyclones?
- How many tropical cyclones will be able to form in the middle latitudes?
- What is the impact of climate change on tropical cyclone formation?
- What is the effect of climate change on tropical cyclones?
- How long does it take for a tropical cyclone to form in the middle latitude?
- How many tropical cyclones will occur in the middle latitudes?
- How many tropical cyclones are likely to form in the midlatitudes?
- How many tropical cyclones are likely to form in the middle latitudes?
- How many tropical cyclones are expected to form in the midlatitudes?
- How many tropical cyclones will be formed in the middle latitudes?
- How many tropical cyclones will there be in the middle latitudes?
- How long will it take for a tropical cyclone to form in the middle latitude?
- What is the impact of global warming on tropical cyclone formation?
- How many tropical cyclones will form in the middle latitudes?
- How many tropical cyclones can we expect to form in the middle latitudes?
- Is it possible for a tropical cyclone to form in the middle latitude?
- What is the effect of climate change on tropical cyclone formation?
- What are the effects of climate change on tropical cyclone formation?
Also you can play with the following parameters in generate method:
-top_k
-top_p