# google-research/pegasus architecture

> Architecture diagram of the GitHub repository google-research/pegasus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-research/pegasus
- Repository: https://github.com/google-research/pegasus

## Overview

##### High-Level Components

a) Core Model Architecture
- Gap Sentences Generation (GSG) pre-training objective
- Various encoder implementations (found in pegasus/flax/models/encoders/):
- Transformer
- BigBird
- Longformer
- Performer
- Local/Global attention variants

b) Data Processing Pipeline (Left Side)
- Input Processing Layer (pegasus/data/)
- Tokenization (pegasus/ops/sp_text_encoder.*)
- Dataset Handlers (public_datasets, pretraining_datasets)

c) Training System (Right Side)
- Training Pipeline (pegasus/bin/train.py)
- Evaluation System (pegasus/eval/)
- Checkpoint Management

##### Component Relationships

- Data flow from raw input through tokenization to model
- Training flow from model output through evaluation metrics
- Pre-training to fine-tuning workflow

##### Specific Implementation Details

- Blue: Core model components
- Green: Data processing components
- Orange: Training/evaluation components
- Purple: External interfaces

##### Key Elements to Highlight

a) Model Architecture Details:
**[Input Text] → [Tokenizer] → [Encoder] → [Decoder] → [Output Summary]**
- ↑
- [Attention Mechanisms]

b) Training Pipeline:
**[Dataset] → [Preprocessor] → [Model] → [Loss Calculation]**
- ↓
- [Evaluation Metrics]
- (ROUGE, BLEU, etc.)

##### Important Subsystems

- Attention mechanisms (pegasus/layers/attention.py)
- Beam search implementation (pegasus/layers/beam_search.py)
- Evaluation metrics system (pegasus/eval/)

##### Technical Specifications

A technical specifications panel showing:
- Supported encoder architectures
- Available preprocessing options
- Evaluation metrics
- Model parameter configurations

##### Implementation Notes

Annotations indicating:
- The FLAX implementation is available for PEGASUS-X
- Multiple encoder architecture options
- Supported dataset formats (TFDS and TFRecords)
- Pre-training and fine-tuning workflows

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Model Architecture"]
        TM["Transformer Model"]:::core
        click TM "https://github.com/google-research/pegasus/blob/main/pegasus/models/transformer.py"
        
        subgraph Encoders["Encoder Implementations"]
            direction TB
            TE["Transformer Encoder"]:::encoder
            BB["BigBird Encoder"]:::encoder
            LF["Longformer Encoder"]:::encoder
            PF["Performer Encoder"]:::encoder
            LA["Local/Global Attention"]:::encoder
        end
        click Encoders "https://github.com/google-research/pegasus/tree/main/pegasus/flax/models/encoders/"
        
        DEC["Decoder"]:::core
        click DEC "https://github.com/google-research/pegasus/tree/main/pegasus/flax/models/decoders/"
        
        ATT["Attention Mechanism"]:::core
        click ATT "https://github.com/google-research/pegasus/blob/main/pegasus/layers/attention.py"
        
        BS["Beam Search"]:::core
        click BS "https://github.com/google-research/pegasus/blob/main/pegasus/layers/beam_search.py"
        
        CL["Common Layers"]:::core
        click CL "https://github.com/google-research/pegasus/blob/main/pegasus/flax/models/shared/common_layers.py"
    end

    subgraph Data["Data Processing Pipeline"]
        DP["Data Processing"]:::data
        click DP "https://github.com/google-research/pegasus/tree/main/pegasus/data/"
        
        TOK["Tokenization"]:::data
        click TOK "https://github.com/google-research/pegasus/blob/main/pegasus/ops/sp_text_encoder.cc"
        
        subgraph DS["Dataset Handlers"]
            PDS["Public Datasets"]:::data
            PTD["Pretraining Datasets"]:::data
        end
        click PDS "https://github.com/google-research/pegasus/blob/main/pegasus/data/public_supervised_datasets.py"
        click PTD "https://github.com/google-research/pegasus/blob/main/pegasus/data/public_pretraining_datasets.py"
        
        IP["Input Pipeline"]:::data
        click IP "https://github.com/google-research/pegasus/blob/main/pegasus/flax/input_pipeline.py"
    end

    subgraph Training["Training System"]
        TP["Training Pipeline"]:::training
        click TP "https://github.com/google-research/pegasus/blob/main/pegasus/bin/train.py"
        
        FT["FLAX Training"]:::training
        click FT "https://github.com/google-research/pegasus/blob/main/pegasus/flax/train.py"
        
        EV["Evaluation System"]:::training
        click EV "https://github.com/google-research/pegasus/tree/main/pegasus/eval/"
        
        CM["Checkpoint Management"]:::training
        click CM "https://github.com/google-research/pegasus/tree/main/pegasus/flax/checkpoint_conversion/"
        
        MP["Model Parameters"]:::training
        click MP "https://github.com/google-research/pegasus/blob/main/pegasus/params/pegasus_params.py"
        
        MC["Model Configurations"]:::training
        click MC "https://github.com/google-research/pegasus/tree/main/pegasus/flax/configs/"
    end

    %% Connections
    DP --> TOK
    TOK --> IP
    IP --> TM
    DS --> DP
    
    TM --> Encoders
    Encoders --> ATT
    ATT --> DEC
    DEC --> BS
    
    TM --> TP
    TP --> EV
    TP --> CM
    
    MP --> TP
    MC --> TP
    CL --> TM

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef data fill:#4CAF50,stroke:#2E7D32,color:white
    classDef training fill:#FF9800,stroke:#EF6C00,color:white
    classDef encoder fill:#9C27B0,stroke:#6A1B9A,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Data Processing"]:::data
        L3["Training Components"]:::training
        L4["Encoder Variants"]:::encoder
    end
```
