模型:
这个模型是在 billsum 数据集上对 led-base-16384 进行微调得到的。
如 Longformer: The Long-Document Transformer 中所述,Iz Beltagy、Matthew E. Peters、Arman Cohan通过基于 bart-base 的初始化让led-base-16384能够处理16K个标记,因为两个模型具有完全相同的架构。为了能够处理16K个标记,bart-base的位置嵌入矩阵被简单地复制了16次。
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
device = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained("d0r1h/LEDBill")
model = AutoModelForSeq2SeqLM.from_pretrained("d0r1h/LEDBill", return_dict_in_generate=True).to(device)
case = "......."
input_ids = tokenizer(case, return_tensors="pt").input_ids.to(device)
global_attention_mask = torch.zeros_like(input_ids)
global_attention_mask[:, 0] = 1
sequences = model.generate(input_ids,
global_attention_mask=global_attention_mask).sequences
summary = tokenizer.batch_decode(sequences,
skip_special_tokens=True)
当该模型用于总结Billsum文档(10个样本)时,它实现了以下结果:
| Model | rouge1-f | rouge1-p | rouge2-f | rouge2-p | rougeL-f | rougeL-p |
|---|---|---|---|---|---|---|
| LEDBill | 34 | 37 | 15 | 16 | 30 | 32 |
| led-base | 2 | 15 | 0 | 0 | 2 | 15 |
This notebook 展示了如何有效地使用led进行总结等下游任务。