Last active
May 10, 2022 09:21
-
-
Save m3hrdadfi/c126524aca81414bbf58043d21034765 to your computer and use it in GitHub Desktop.
NLP Summarization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input_ids = tokenizer('summarize: ' + text.lower(), | |
return_tensors='pt').input_ids.to(model.device) | |
output = model.generate( | |
input_ids, | |
max_length=200, | |
num_beams=8, | |
num_beam_groups=4, # based on this paper, https://arxiv.org/pdf/1610.02424.pdf | |
no_repeat_ngram_size=2 | |
) | |
generated = tokenizer.decode(output[0], skip_special_tokens=True) | |
print(generated) | |
# >>> chalmers university of technology is a swedish university located in gothenburg. the university was founded in 1829 after he donated part of his fortune to the establishment of an "industrial school" the school is one of only three universities named after an individual, the other two being karolinska institutet and linnaeus university. | |
# >>> {'rouge1': Score(precision=0.9615384615384616, recall=0.37593984962406013, fmeasure=0.5405405405405406), | |
# >>> 'rouge2': Score(precision=0.7647058823529411, recall=0.29545454545454547, fmeasure=0.42622950819672134), | |
# >>> 'rougeL': Score(precision=0.9230769230769231, recall=0.3609022556390977, fmeasure=0.518918918918919)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment