Views
No views yet
| Set | Metric | Value |
|---|---|---|
| Test | Rouge2 - mid -precision | 9.6 |
| Test | Rouge2 - mid - recall | 8.4 |
| Test | Rouge2 - mid - fmeasure | 8.7 |
| Test | Rouge1 | 26.24 |
| Test | Rouge2 | 8.9 |
| Test | RougeL | 21.01 |
| Test | RougeLsum | 21.02 |
1import torch
2from transformers import BertTokenizerFast, EncoderDecoderModel
3device = 'cuda' if torch.cuda.is_available() else 'cpu'
4ckpt = 'mrm8488/bert2bert_shared-spanish-finetuned-summarization'
5tokenizer = BertTokenizerFast.from_pretrained(ckpt)
6model = EncoderDecoderModel.from_pretrained(ckpt).to(device)
7
8def generate_summary(text):
9
10 inputs = tokenizer([text], padding="max_length", truncation=True, max_length=512, return_tensors="pt")
11 input_ids = inputs.input_ids.to(device)
12 attention_mask = inputs.attention_mask.to(device)
13 output = model.generate(input_ids, attention_mask=attention_mask)
14 return tokenizer.decode(output[0], skip_special_tokens=True)
15
16text = "Your text here..."
17generate_summary(text)Created by Manuel Romero/@mrm8488 with the support of Narrativa
Made with ♥ in Spain