# acolas1/gap_coling2022 architecture

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

- Interactive diagram: https://gitdiagram.com/acolas1/gap_coling2022
- Repository: https://github.com/acolas1/gap_coling2022

## Overview

##### Project type and purpose
- This is a Python-based research framework for Knowledge Graph-to-Text generation (GAP).
- It integrates graph-aware components into a pre-trained language model (BART).
- Provides CLI scripts for fine-tuning, inference, and evaluation on benchmark datasets (WebNLG, EventNarrative).

##### File structure
- Top-level scripts:
- run_gap.py, cli_gap.py – orchestrate end-to-end flows
- modeling_gap.py, modeling_gap_type.py – define the graph-aware model architectures
- data_relations_as_nodes.py – a preprocessing helper
- finetune.sh, infer.sh – bash wrappers for training and generation
- Directory eval_webnlg:
- measure_scores.py and subpackage pycocoevalcap – evaluation scripts for BLEU, METEOR, ROUGE, CIDEr
- Directories implied by README (data/, pretrained_LM/, out/) – not present in tree but required for data, model checkpoints, outputs.

##### README for additional insights
- Core components:
- Pretrained LM (BART) stored in pretrained_LM/
- Datasets in data/
- Outputs (models, logs, generated text) in out/
- Evaluation uses external jars (Stanford CoreNLP, METEOR) in eval_webnlg.

##### Main components
a. Data Preparation
- Input: raw KG data (WebNLG/EventNarrative) in data/
- Scripts: data_relations_as_nodes.py, tokenization via Transformers
b. Model Architecture
- Base: Huggingface BART model
- Graph-aware extensions:
- Mask structure for neighborhood information (modeling_gap.py)
- Type encoder bias for edge types (modeling_gap_type.py)
c. Training Pipeline
- Script: finetune.sh → run_gap.py → modeling_gap*.py
- Framework: PyTorch + torch-scatter + Transformers
- Outputs: fine-tuned checkpoints in out/
d. Inference Pipeline
- Script: infer.sh → cli_gap.py or run_gap.py
- Loads checkpoint from out/, generates text from KG input
- Writes generated output files to out/
e. Evaluation Pipeline
- Directory: eval_webnlg/
- measure_scores.py calls pycocoevalcap to compute BLEU, ROUGE, METEOR, CIDEr
- Dependencies: Stanford CoreNLP jar, meteor jar

##### Relationships and interactions
Data Preparation → Training Pipeline → Out (checkpoints)
Out + Data Preparation → Inference Pipeline → Out (generated text)
Generated text + Reference data → Evaluation Pipeline → Evaluation reports
- External dependencies:
- Huggingface model repo → pretrained_LM/
- External jars in eval_webnlg/pycocoevalcap/meteor and tokenizer

##### Architectural patterns and design principles
- Modular separation: preprocessing, modeling, training, inference, evaluation
- Reuse of existing tooling (Huggingface Transformers, pycocoevalcap)
- Parameterization via CLI flags (masking options, type encoding)

##### Elements
- Rectangles for processes (Preprocessing, Training, Inference, Evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Layer"
        DataRaw["Raw KG Data (data/)"]:::data
        Prep["Preprocessing\ndata_relations_as_nodes.py"]:::process
        Tokenize["Tokenization\n(Transformers)"]:::process
    end

    subgraph "Model Layer"
        LM["Pretrained BART\n(pretrained_LM/)"]:::model
        GapEnc["Graph-aware Encoder\nmodeling_gap.py"]:::model
        TypeEnc["Type Encoder Bias\nmodeling_gap_type.py"]:::model
    end

    subgraph "Training Pipeline"
        ShellTrain["finetune.sh"]:::process
        RunTrain["run_gap.py"]:::process
    end

    subgraph "Inference Pipeline"
        ShellInfer["infer.sh"]:::process
        CLI["cli_gap.py"]:::process
    end

    subgraph "Output Store"
        Out["Outputs (out/)"]:::data
    end

    subgraph "Evaluation Pipeline"
        EvalEntry["measure_scores.py"]:::evaluate
        COCO["pycocoevalcap"]:::evaluate
        BLEU["BLEU\nbleu.py"]:::evaluate
        ROUGE["ROUGE\nrouge.py"]:::evaluate
        CIDEr["CIDEr\ncider.py"]:::evaluate
        METEOR["METEOR\nmeteor.py"]:::evaluate
        Tokenizer["CoreNLP Tokenizer\nptbtokenizer.py"]:::evaluate
        ExtJars["Stanford CoreNLP\nMETEOR JAR"]:::external
    end

    subgraph "Libraries & Docs"
        Torch["PyTorch\n torch-scatter"]:::external
        Transformers["Transformers"]:::external
        README["README.md"]:::external
    end

    %% Data Flow for Training
    DataRaw --> Prep
    Prep --> Tokenize
    Tokenize --> RunTrain
    LM --> RunTrain
    GapEnc --> RunTrain
    TypeEnc --> RunTrain
    ShellTrain --> RunTrain
    RunTrain --> Out

    %% Data Flow for Inference
    DataRaw --> CLI
    Out --> CLI
    LM --> CLI
    GapEnc --> CLI
    TypeEnc --> CLI
    ShellInfer --> CLI
    CLI --> Out

    %% Data Flow for Evaluation
    Out --> EvalEntry
    DataRaw --> EvalEntry
    EvalEntry --> BLEU
    EvalEntry --> ROUGE
    EvalEntry --> CIDEr
    EvalEntry --> METEOR
    EvalEntry --> Tokenizer
    COCO --> BLEU
    COCO --> ROUGE
    COCO --> CIDEr
    COCO --> METEOR
    COCO --> Tokenizer
    ExtJars --> METEOR
    ExtJars --> Tokenizer

    %% Library Dependencies
    Torch --> RunTrain
    Transformers --> Tokenize
    Transformers --> RunTrain
    Transformers --> CLI

    %% Click Events
    click Prep "https://github.com/acolas1/gap_coling2022/blob/main/data_relations_as_nodes.py"
    click GapEnc "https://github.com/acolas1/gap_coling2022/blob/main/modeling_gap.py"
    click TypeEnc "https://github.com/acolas1/gap_coling2022/blob/main/modeling_gap_type.py"
    click ShellTrain "https://github.com/acolas1/gap_coling2022/blob/main/finetune.sh"
    click RunTrain "https://github.com/acolas1/gap_coling2022/blob/main/run_gap.py"
    click ShellInfer "https://github.com/acolas1/gap_coling2022/blob/main/infer.sh"
    click CLI "https://github.com/acolas1/gap_coling2022/blob/main/cli_gap.py"
    click EvalEntry "https://github.com/acolas1/gap_coling2022/blob/main/eval_webnlg/measure_scores.py"
    click COCO "https://github.com/acolas1/gap_coling2022/tree/main/eval_webnlg/pycocoevalcap"
    click BLEU "https://github.com/acolas1/gap_coling2022/blob/main/eval_webnlg/pycocoevalcap/bleu/bleu.py"
    click ROUGE "https://github.com/acolas1/gap_coling2022/blob/main/eval_webnlg/pycocoevalcap/rouge/rouge.py"
    click CIDEr "https://github.com/acolas1/gap_coling2022/blob/main/eval_webnlg/pycocoevalcap/cider/cider.py"
    click METEOR "https://github.com/acolas1/gap_coling2022/blob/main/eval_webnlg/pycocoevalcap/meteor/meteor.py"
    click Tokenizer "https://github.com/acolas1/gap_coling2022/blob/main/eval_webnlg/pycocoevalcap/tokenizer/ptbtokenizer.py"
    click README "https://github.com/acolas1/gap_coling2022/blob/main/README.md"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#000;
    classDef model fill:#90EE90,stroke:#000;
    classDef process fill:#FFFF99,stroke:#000;
    classDef evaluate fill:#FFA500,stroke:#000;
    classDef external fill:#D3D3D3,stroke:#000;
```
