模型:
mrm8488/bert-mini2bert-mini-finetuned-cnn_daily_mail-summarization
该模型是在CNN/Dailymail摘要数据集上微调的Bert-mini2Bert-mini( mini )模型。
该模型在CNN/Dailymail的测试数据集上取得了16.51的ROUGE-2分数。
有关模型微调的更多细节,请参阅 this 笔记本。
Metric | # Value |
---|---|
ROUGE-2 | 16.51 |
from transformers import BertTokenizerFast, EncoderDecoderModel import torch device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') tokenizer = BertTokenizerFast.from_pretrained('mrm8488/bert-mini2bert-mini-finetuned-cnn_daily_mail-summarization') model = EncoderDecoderModel.from_pretrained('mrm8488/bert-mini2bert-mini-finetuned-cnn_daily_mail-summarization').to(device) def generate_summary(text): # cut off at BERT max length 512 inputs = tokenizer([text], padding="max_length", truncation=True, max_length=512, return_tensors="pt") input_ids = inputs.input_ids.to(device) attention_mask = inputs.attention_mask.to(device) output = model.generate(input_ids, attention_mask=attention_mask) return tokenizer.decode(output[0], skip_special_tokens=True) text = "your text to be summarized here..." generate_summary(text)
由 Manuel Romero/@mrm8488 | LinkedIn 创建
在西班牙制作♥