Downloads · 30 days
23
15% of all-time downloads
andreaparker/long-summ
long-summ is a summarization model from andreaparker. Use it when you need a shorter version of a longer text. It is set up for transformers. The card lists the license as apache-2.0.
<a href="https://colab.research.google.com/gist/pszemraj/3eba944ddc9fc9a4a1bfb21e83b57620/summarization-token-batching.ipynb" <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/ </a
Downloads · 30 days
23
15% of all-time downloads
All-time downloads
155
Public
Repo size
1.2 MB
Likes
0
Public
Click a slice to open those files.
.json2.9 MB · 85%
From the Hugging Face model README
A fine-tuned version of allenai/led-large-16384 on the BookSum dataset.
Goal: a model that can generalize well and is useful in summarizing long text in academic and daily usage. The result works well on lots of text and can handle 16384 tokens/batch (if you have the GPU memory to handle that)
Note: the API is set to generate a max of 64 tokens for runtime reasons, so the summaries may be truncated (depending on the length of input text). For best results use python as below.
encoder_no_repeat_ngram_size=3 when calling the pipeline object to improve summary quality.
Load the model into a pipeline object:
import torch
from transformers import pipeline
hf_name = 'pszemraj/led-large-book-summary'
summarizer = pipeline(
"summarization",
hf_name,
device=0 if torch.cuda.is_available() else -1,
)
wall_of_text = "your words here"
result = summarizer(
wall_of_text,
min_length=16,
max_length=256,
no_repeat_ngram_size=3,
encoder_no_repeat_ngram_size=3,
repetition_penalty=3.5,
num_beams=4,
early_stopping=True,
)
Note: The global attention mask needs to be used when decoding to generate the best-quality summaries:
generate_batch function for more details; note the beam search as well; we've pasted the function below for easy referenceimport torch
def generate_answer(batch):
inputs_dict = tokenizer(batch["article"], padding="max_length", max_length=16384, return_tensors="pt", truncation=True)
input_ids = inputs_dict.input_ids.to("cuda")
attention_mask = inputs_dict.attention_mask.to("cuda")
global_attention_mask = torch.zeros_like(attention_mask)
# put global attention on <s> token
global_attention_mask[:, 0] = 1
predicted_abstract_ids = model.generate(input_ids, attention_mask=attention_mask, global_attention_mask=global_attention_mask, max_length=512, num_beams=4)
batch["predicted_abstract"] = tokenizer.batch_decode(predicted_abstract_ids, skip_special_tokens=True)
return batch
chapter, and the output was summary_textThe following hyperparameters were used during training:
Unfortunately, don't have all records on-hand for middle epochs; the following should be representative:
The following hyperparameters were used during training: