Views
No views yet
| Set | Metric | # Score |
|---|---|---|
| Test | Rouge2 - mid -precision | 33.04 |
| Test | Rouge2 - mid - recall | 33.83 |
| Test | Rouge2 - mid - fmeasure | 33.15 |
1import torch
2from transformers import BertTokenizerFast, EncoderDecoderModel
3device = 'cuda' if torch.cuda.is_available() else 'cpu'
4ckpt = 'mrm8488/bert2bert_shared-german-finetuned-summarization'
5tokenizer = BertTokenizerFast.from_pretrained(ckpt)
6model = EncoderDecoderModel.from_pretrained(ckpt).to(device)
7def generate_summary(text):
8 inputs = tokenizer([text], padding="max_length", truncation=True, max_length=512, return_tensors="pt")
9 input_ids = inputs.input_ids.to(device)
10 attention_mask = inputs.attention_mask.to(device)
11 output = model.generate(input_ids, attention_mask=attention_mask)
12 return tokenizer.decode(output[0], skip_special_tokens=True)
13
14text = "Your text here..."
15
16generate_summary(text)
17