# idirlab/graphnarrator architecture

> Architecture diagram of the GitHub repository idirlab/graphnarrator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/idirlab/graphnarrator
- Repository: https://github.com/idirlab/graphnarrator

## Overview

Graph Narrator turns knowledge-graph triples into natural-language descriptions. Its principal workflow is to preprocess graph-and-text examples, train a sequence-to-sequence model, then decode graph input into a narrative. The README documents both T5 and BART training and decoding, plus model variants and WebNLG fine-tuning. The graph includes shared training infrastructure and evaluation helpers; some script wiring and model internals were not sampled, so those connections are omitted rather than inferred.

Main entry points: [`graphnarrator/finetune.py`](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/finetune.py) (Training and decoding), [`graphnarrator/utils_graph2text.py`](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/utils_graph2text.py) (Graph-text metrics), [`graphnarrator/data/generate_input_graphnarrative.py`](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/data/generate_input_graphnarrative.py) (Triple preprocessing), [`graphnarrator/utils.py`](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/utils.py) (Seq2seq datasets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_preparation["Data preparation"]
  node_corpus["Graph-text corpus"]
  node_preprocess["Triple preprocessing"]
  node_seqdata["Seq2seq datasets<br/>[utils.py]"]
end

subgraph group_learning["Model training"]
  node_trainer["Training and decoding<br/>[finetune.py]"]
  node_transformer["Transformer base<br/>[lightning_base.py]"]
  node_callbacks["Training callbacks<br/>[callbacks.py]"]
end

subgraph group_generation["Narrative generation"]
  node_graph2text["Graph-to-text task<br/>[finetune.py]"]
  node_graphinput["Triple input"]
  node_narrative["Generated narrative"]
end

subgraph group_evaluation["Evaluation"]
  node_metrichelpers["Graph-text metrics"]
  node_bleu["BLEU scorer<br/>[multi-bleu.perl]"]
  node_meteor["METEOR references"]
  node_chrf["chrF++ scorer<br/>[chrf++.py]"]
end

node_user(("Researcher"))

node_user -.->|"provides examples"| node_corpus
node_corpus -.->|"supplies XML"| node_preprocess
node_preprocess -.->|"formats examples"| node_seqdata
node_user -->|"starts training"| node_trainer
node_trainer -->|"loads datasets"| node_seqdata
node_trainer -->|"inherits from"| node_transformer
node_trainer -->|"uses callbacks"| node_callbacks
node_trainer -->|"defines task"| node_graph2text
node_user -->|"provides triples"| node_graphinput
node_graphinput -->|"formats as graph"| node_graph2text
node_graph2text -->|"generates text"| node_narrative
node_user -.->|"requests scoring"| node_metrichelpers
node_metrichelpers -->|"runs scorer"| node_bleu
node_metrichelpers -->|"runs scorer"| node_chrf
node_metrichelpers -.->|"prepares references"| node_meteor

click node_preprocess "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/data/generate_input_graphnarrative.py"
click node_seqdata "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/utils.py"
click node_trainer "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/finetune.py"
click node_transformer "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/lightning_base.py"
click node_callbacks "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/callbacks.py"
click node_graph2text "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/finetune.py"
click node_metrichelpers "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/utils_graph2text.py"
click node_bleu "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/data/multi-bleu.perl"
click node_meteor "https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/data/convert_files_meteor.py"
click node_chrf "https://github.com/idirlab/graphnarrator/blob/master/utils/chrf%2B%2B.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_corpus,node_preprocess,node_seqdata toneBlue
class node_trainer,node_transformer,node_callbacks toneAmber
class node_graph2text,node_graphinput,node_narrative toneMint
class node_metrichelpers,node_bleu,node_meteor,node_chrf toneRose
class node_user toneIndigo
```

## Components

### Data preparation

- **Graph-text corpus**
- [Triple preprocessing](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/data/generate_input_graphnarrative.py): `graphnarrator/data/generate_input_graphnarrative.py`
- [Seq2seq datasets](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/utils.py): `graphnarrator/utils.py`

### Model training

- [Training and decoding](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/finetune.py): `graphnarrator/finetune.py`
- [Transformer base](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/lightning_base.py): `graphnarrator/lightning_base.py`
- [Training callbacks](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/callbacks.py): `graphnarrator/callbacks.py`

### Narrative generation

- [Graph-to-text task](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/finetune.py): `graphnarrator/finetune.py`
- **Triple input**
- **Generated narrative**

### Evaluation

- [Graph-text metrics](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/utils_graph2text.py): `graphnarrator/utils_graph2text.py`
- [BLEU scorer](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/data/multi-bleu.perl): `graphnarrator/data/multi-bleu.perl`
- [METEOR references](https://github.com/idirlab/graphnarrator/blob/master/graphnarrator/data/convert_files_meteor.py): `graphnarrator/data/convert_files_meteor.py`
- [chrF++ scorer](https://github.com/idirlab/graphnarrator/blob/master/utils/chrf%2B%2B.py): `utils/chrf++.py`

### Other components

- **Researcher**

## Connections

- Researcher → Graph-text corpus: provides examples
- Graph-text corpus → Triple preprocessing: supplies XML
- Triple preprocessing → Seq2seq datasets: formats examples
- Researcher → Training and decoding: starts training (evidence: `README.md`)
- Training and decoding → Seq2seq datasets: loads datasets (evidence: `graphnarrator/finetune.py`)
- Training and decoding → Transformer base: inherits from (evidence: `graphnarrator/finetune.py`)
- Training and decoding → Training callbacks: uses callbacks (evidence: `graphnarrator/finetune.py`)
- Training and decoding → Graph-to-text task: defines task (evidence: `graphnarrator/finetune.py`)
- Researcher → Triple input: provides triples (evidence: `README.md`)
- Triple input → Graph-to-text task: formats as graph (evidence: `README.md`)
- Graph-to-text task → Generated narrative: generates text (evidence: `graphnarrator/finetune.py`)
- Researcher → Graph-text metrics: requests scoring
- Graph-text metrics → BLEU scorer: runs scorer (evidence: `graphnarrator/utils_graph2text.py`)
- Graph-text metrics → chrF++ scorer: runs scorer (evidence: `graphnarrator/utils_graph2text.py`)
- Graph-text metrics → METEOR references: prepares references
