kmfoda/booksum
Viewer • Updated • 12.5k • 1.93k • 80
How to use pszemraj/bigbird-pegasus-large-K-booksum with Transformers:
# Use a pipeline as a high-level helper
# Warning: Pipeline type "summarization" is no longer supported in transformers v5.
# You must load the model directly (see below) or downgrade to v4.x with:
# 'pip install "transformers<5.0.0'
from transformers import pipeline
pipe = pipeline("summarization", model="pszemraj/bigbird-pegasus-large-K-booksum") # Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("pszemraj/bigbird-pegasus-large-K-booksum")
model = AutoModelForSeq2SeqLM.from_pretrained("pszemraj/bigbird-pegasus-large-K-booksum")this is the "latest" version of the model that has been trained the longest, currently at 70k steps
google/bigbird-pegasus-large-bigpatentAn extended example, including a demo of batch summarization, is here.
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from transformers import pipeline
model = AutoModelForSeq2SeqLM.from_pretrained(
"pszemraj/bigbird-pegasus-large-K-booksum",
low_cpu_mem_usage=True,
)
tokenizer = AutoTokenizer.from_pretrained(
"pszemraj/bigbird-pegasus-large-K-booksum",
)
summarizer = pipeline(
"summarization",
model=model,
tokenizer=tokenizer,
)
wall_of_text = "your text to be summarized goes here."
result = summarizer(
wall_of_text,
min_length=16,
max_length=256,
no_repeat_ngram_size=3,
clean_up_tokenization_spaces=True,
)
print(result[0]["summary_text"])