Skip to content

Language models, retrieval, prompting, and language adaptation · Encoder–decoder and multilingual models · LNG025 · Model

PEGASUS

Pretrains summarization-oriented encoder–decoders by removing important sentences and asking the model to generate them from the remaining document.

Explained here Component demo, not a trained model CodeSplash's own run

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's own run
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Pretrains summarization-oriented encoder–decoders by removing important sentences and asking the model to generate them from the remaining document. The training task is designed to resemble producing an abstract of salient content.

Question / objective

Can predicting salient missing sentences prepare a model for summarization?

Architecture / computational structure

An encoder–decoder reconstructs selected gap sentences from the remaining document. Learned encoder/decoder weights are parameters; gap selection, removal fraction, context length, and decoding penalties are hyperparameters.

Assumptions

Heuristic sentence importance may favor lexical overlap rather than factual or domain-specific relevance.

Formula / computational definition

LGSG=−log⁡pθ(xS∣x∖S),S⊆{1,…,number of sentences}.\mathcal L_{\mathrm{GSG}}=-\log p_\theta(x_S\mid x_{\setminus S}),\qquad S\subseteq\{1,\ldots,\text{number of sentences}\}.

Select a sentence set S from document x, remove it to obtain x_without_S, and minimize -log p_theta(x_S|x_without_S). Gap-sentence selection can use salience heuristics; target construction and ordering are part of the learning objective.

Parameters and notation

Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Fraction of removed sentences, salience-selection rule, document length, vocabulary, encoder/decoder size, and downstream summary length controls.

Fitting, fine-tuning, and adaptation

Fine-tune on source/summary pairs with conditional cross-entropy, optionally freezing the encoder or using compatible adapters. Match summary length and domain to deployment. Select checkpoints with factuality-aware validation and inspect entity/numeric errors, since overlap-based scores can reward unsupported summaries.

How to use and calibrate

Assess summary informativeness, factual consistency, coverage, redundancy, and length sensitivity alongside automatic overlap metrics. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.

Example application

Produce scientific-article abstracts while auditing whether key numerical claims remain supported.

Interpretation / pitfalls

Watch out

Documents exceeding the context budget lose evidence, and generated summaries may conflate entities or numbers. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.

Python and R code examples

Full implementation route: Use documented PEGASUS models in Transformers from Python; R can call the same tokenizer and generation path via reticulate. A native sentence-selection toy demonstrates target construction, while full pretraining requires a large corpus and compute.

Example scope: PEGASUS-style gap-sentence target construction from externally assigned salience scores.

Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.

Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — PEGASUS-style gap-sentence target construction from externally assigned salience scores.

Shared setup for this chapter
import math

def softmax(xs):
    m = max(xs)
    es = [math.exp(x-m) for x in xs]
    return [e/sum(es) for e in es]

def dot(a, b):
    return sum(x*y for x, y in zip(a, b))

def matvec(matrix, vector):
    return [dot(row, vector) for row in matrix]

def meanvec(rows):
    return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]

def sigmoid(x):
    return 1/(1+math.exp(-x))

def nll(probabilities):
    return -sum(math.log(p) for p in probabilities)
sentences = ["Demand grew.","Sales rose 12%.","The office opened Monday."]
salience = [0.5,0.9,0.1]
gap = max(range(3), key=salience.__getitem__)
print({"input": [s for i,s in enumerate(sentences) if i != gap], "target": sentences[gap]})
R

Component demo, not a trained model — PEGASUS-style gap-sentence target construction from externally assigned salience scores.

Shared setup for this chapter
softmax <- function(x) {
  shifted <- exp(x-max(x))
  shifted/sum(shifted)
}
sentences <- c("Demand grew.","Sales rose 12%.","The office opened Monday.")
salience <- c(0.5,0.9,0.1); gap <- which.max(salience)
print(list(input=sentences[-gap], target=sentences[gap]))

Sources

From the CodeSplash reference, entry LNG025.