# ansh2508/han-fake-news-detector architecture

> Architecture diagram of the GitHub repository ansh2508/han-fake-news-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ansh2508/han-fake-news-detector
- Repository: https://github.com/ansh2508/han-fake-news-detector

## Overview

This repository trains and evaluates a hierarchical attention network for fake-news classification. The main workflow is preparing labeled text as hierarchical token sequences, training the HAN, and evaluating classification performance; a separate notebook evaluates the saved model on another dataset. The source shows the preprocessing, model, and trainer implementations, while README statements describe notebook-level workflows and outputs. Notebook internals were not sampled, so their links to implementation stages are documented only where supported.

Main entry points: [`pipeline.ipynb`](https://github.com/ansh2508/han-fake-news-detector/blob/main/pipeline.ipynb) (Training pipeline), [`src/model_trainer.py`](https://github.com/ansh2508/han-fake-news-detector/blob/main/src/model_trainer.py) (Model trainer), [`external_dataset_test.ipynb`](https://github.com/ansh2508/han-fake-news-detector/blob/main/external_dataset_test.ipynb) (External evaluation), [`src/data_preprocessor.py`](https://github.com/ansh2508/han-fake-news-detector/blob/main/src/data_preprocessor.py) (Text preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_fake_data["Fake articles<br/>[Fake.csv]"]
  node_true_data["True articles<br/>[True.csv]"]
  node_preprocessor["Text preprocessing"]
  node_dataset["Hierarchical dataset"]
  node_vocabulary["Saved vocabulary<br/>[vocabulary.pkl]"]
end

subgraph group_model["HAN modeling"]
  node_trainer["Model trainer<br/>[model_trainer.py]"]
  node_han["HAN classifier<br/>[han_model.py]"]
end

subgraph group_evaluation["Evaluation and results"]
  node_training_notebook["Training pipeline<br/>[pipeline.ipynb]"]
  node_checkpoint["Model checkpoint"]
  node_external_notebook["External evaluation"]
  node_model_card["Model card"]
  node_plots["Evaluation plots"]
end

node_researcher(("Researcher"))

node_researcher -->|"runs"| node_training_notebook
node_fake_data -.->|"training input"| node_training_notebook
node_true_data -.->|"training input"| node_training_notebook
node_training_notebook -.->|"uses preprocessing"| node_preprocessor
node_preprocessor -->|"encodes text"| node_dataset
node_training_notebook -.->|"trains model"| node_trainer
node_trainer -->|"constructs and trains"| node_han
node_trainer -->|"uses prediction utilities"| node_preprocessor
node_trainer -->|"saves and loads"| node_checkpoint
node_training_notebook -->|"produces"| node_checkpoint
node_training_notebook -->|"generates"| node_plots
node_researcher -->|"runs"| node_external_notebook
node_external_notebook -->|"loads"| node_checkpoint
node_external_notebook -->|"loads"| node_vocabulary
node_external_notebook -.->|"evaluates text"| node_preprocessor
node_training_notebook -.->|"records results"| node_model_card

click node_training_notebook "https://github.com/ansh2508/han-fake-news-detector/blob/main/pipeline.ipynb"
click node_fake_data "https://github.com/ansh2508/han-fake-news-detector/blob/main/data/Fake.csv"
click node_true_data "https://github.com/ansh2508/han-fake-news-detector/blob/main/data/True.csv"
click node_preprocessor "https://github.com/ansh2508/han-fake-news-detector/blob/main/src/data_preprocessor.py"
click node_dataset "https://github.com/ansh2508/han-fake-news-detector/blob/main/src/data_preprocessor.py"
click node_trainer "https://github.com/ansh2508/han-fake-news-detector/blob/main/src/model_trainer.py"
click node_han "https://github.com/ansh2508/han-fake-news-detector/blob/main/src/han_model.py"
click node_external_notebook "https://github.com/ansh2508/han-fake-news-detector/blob/main/external_dataset_test.ipynb"
click node_vocabulary "https://github.com/ansh2508/han-fake-news-detector/blob/main/vocabulary.pkl"
click node_plots "https://github.com/ansh2508/han-fake-news-detector/tree/main/plots"

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_fake_data,node_true_data,node_preprocessor,node_dataset,node_vocabulary toneBlue
class node_trainer,node_han toneAmber
class node_training_notebook,node_checkpoint,node_external_notebook,node_model_card,node_plots toneMint
class node_researcher toneIndigo
```

## Components

### Data preparation

- [Fake articles](https://github.com/ansh2508/han-fake-news-detector/blob/main/data/Fake.csv): `data/Fake.csv`
- [True articles](https://github.com/ansh2508/han-fake-news-detector/blob/main/data/True.csv): `data/True.csv`
- [Text preprocessing](https://github.com/ansh2508/han-fake-news-detector/blob/main/src/data_preprocessor.py): `src/data_preprocessor.py`
- [Hierarchical dataset](https://github.com/ansh2508/han-fake-news-detector/blob/main/src/data_preprocessor.py): `src/data_preprocessor.py`
- [Saved vocabulary](https://github.com/ansh2508/han-fake-news-detector/blob/main/vocabulary.pkl): `vocabulary.pkl`

### HAN modeling

- [Model trainer](https://github.com/ansh2508/han-fake-news-detector/blob/main/src/model_trainer.py): `src/model_trainer.py`
- [HAN classifier](https://github.com/ansh2508/han-fake-news-detector/blob/main/src/han_model.py): `src/han_model.py`

### Evaluation and results

- [Training pipeline](https://github.com/ansh2508/han-fake-news-detector/blob/main/pipeline.ipynb): `pipeline.ipynb`
- **Model checkpoint**
- [External evaluation](https://github.com/ansh2508/han-fake-news-detector/blob/main/external_dataset_test.ipynb): `external_dataset_test.ipynb`
- **Model card**
- [Evaluation plots](https://github.com/ansh2508/han-fake-news-detector/tree/main/plots): `plots`

### Other components

- **Researcher**

## Connections

- Researcher → Training pipeline: runs (evidence: `README.md`)
- Fake articles → Training pipeline: training input
- True articles → Training pipeline: training input
- Training pipeline → Text preprocessing: uses preprocessing
- Text preprocessing → Hierarchical dataset: encodes text (evidence: `src/data_preprocessor.py`)
- Training pipeline → Model trainer: trains model
- Model trainer → HAN classifier: constructs and trains (evidence: `src/model_trainer.py`)
- Model trainer → Text preprocessing: uses prediction utilities (evidence: `src/model_trainer.py`)
- Model trainer → Model checkpoint: saves and loads (evidence: `src/model_trainer.py`)
- Training pipeline → Model checkpoint: produces (evidence: `README.md`)
- Training pipeline → Evaluation plots: generates (evidence: `README.md`)
- Researcher → External evaluation: runs (evidence: `README.md`)
- External evaluation → Model checkpoint: loads (evidence: `README.md`)
- External evaluation → Saved vocabulary: loads (evidence: `README.md`)
- External evaluation → Text preprocessing: evaluates text
- Training pipeline → Model card: records results
