# alisakour/hal-attention-pooling architecture

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

- Interactive diagram: https://gitdiagram.com/alisakour/hal-attention-pooling
- Repository: https://github.com/alisakour/hal-attention-pooling

## Overview

This is a PyTorch research application for IMDB sentiment classification, comparing classic HAL mean pooling with temperature-scaled attention pooling. The main workflow loads and tokenizes IMDB reviews, builds HAL embeddings and data loaders, trains and evaluates both models, then saves the best attention model. A separate inference script rebuilds the vocabulary and embeddings, loads that checkpoint, and predicts sentiment with attention weights. Relationships are based on the README and shown source; no additional unsampled subsystems are inferred.

Main entry points: [`train.py`](https://github.com/alisakour/hal-attention-pooling/blob/main/train.py) (Training Pipeline), [`inference.py`](https://github.com/alisakour/hal-attention-pooling/blob/main/inference.py) (Inference Pipeline), [`data_utils.py`](https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py) (Dataset Loading), [`models.py`](https://github.com/alisakour/hal-attention-pooling/blob/main/models.py) (Attention Model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data Preparation"]
  node_loader["Dataset Loading<br/>[data_utils.py]"]
  node_vocab["Vocabulary and Tokens<br/>[data_utils.py]"]
  node_hal["HAL Embeddings<br/>[data_utils.py]"]
  node_batches["Data Loaders<br/>[data_utils.py]"]
end

subgraph group_models["Sentiment Models"]
  node_baseline["Mean Pooling Model<br/>[models.py]"]
  node_attention["Attention Model<br/>[models.py]"]
end

subgraph group_training["Training and Evaluation"]
  node_pipeline["Training Pipeline<br/>[train.py]"]
  node_evaluation["Training and Evaluation<br/>[train.py]"]
  node_plots["Metric Plots<br/>[train.py]"]
  node_checkpoint["Model Checkpoint"]
end

subgraph group_inference["Inference"]
  node_inference["Inference Pipeline<br/>[inference.py]"]
  node_prediction["Sentiment and Attention<br/>[inference.py]"]
end

node_operator(("Researcher"))
node_imdb[("IMDB Dataset")]

node_loader -->|"loads"| node_imdb
node_loader -->|"builds vocabulary"| node_vocab
node_pipeline -->|"loads data"| node_loader
node_pipeline -->|"builds embeddings"| node_hal
node_pipeline -->|"creates loaders"| node_batches
node_pipeline -->|"initializes"| node_baseline
node_pipeline -->|"initializes"| node_attention
node_pipeline -->|"trains and evaluates"| node_evaluation
node_evaluation -->|"saves best weights"| node_checkpoint
node_pipeline -->|"plots metrics"| node_plots
node_operator -->|"runs training"| node_pipeline
node_operator -.->|"runs inference"| node_inference
node_inference -->|"loads data"| node_loader
node_inference -->|"builds embeddings"| node_hal
node_inference -->|"initializes model"| node_attention
node_inference -->|"loads weights"| node_checkpoint
node_inference -->|"predicts sentiment"| node_prediction
node_attention -->|"returns logits and weights"| node_prediction

click node_loader "https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py"
click node_vocab "https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py"
click node_hal "https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py"
click node_batches "https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py"
click node_baseline "https://github.com/alisakour/hal-attention-pooling/blob/main/models.py"
click node_attention "https://github.com/alisakour/hal-attention-pooling/blob/main/models.py"
click node_pipeline "https://github.com/alisakour/hal-attention-pooling/blob/main/train.py"
click node_evaluation "https://github.com/alisakour/hal-attention-pooling/blob/main/train.py"
click node_plots "https://github.com/alisakour/hal-attention-pooling/blob/main/train.py"
click node_inference "https://github.com/alisakour/hal-attention-pooling/blob/main/inference.py"
click node_prediction "https://github.com/alisakour/hal-attention-pooling/blob/main/inference.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_loader,node_vocab,node_hal,node_batches toneBlue
class node_baseline,node_attention,node_imdb toneAmber
class node_pipeline,node_evaluation,node_plots,node_checkpoint toneMint
class node_inference,node_prediction toneRose
class node_operator toneIndigo
```

## Components

### Data Preparation

- [Dataset Loading](https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py): `data_utils.py`
- [Vocabulary and Tokens](https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py): `data_utils.py`
- [HAL Embeddings](https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py): `data_utils.py`
- [Data Loaders](https://github.com/alisakour/hal-attention-pooling/blob/main/data_utils.py): `data_utils.py`

### Sentiment Models

- [Mean Pooling Model](https://github.com/alisakour/hal-attention-pooling/blob/main/models.py): `models.py`
- [Attention Model](https://github.com/alisakour/hal-attention-pooling/blob/main/models.py): `models.py`

### Training and Evaluation

- [Training Pipeline](https://github.com/alisakour/hal-attention-pooling/blob/main/train.py): `train.py`
- [Training and Evaluation](https://github.com/alisakour/hal-attention-pooling/blob/main/train.py): `train.py`
- [Metric Plots](https://github.com/alisakour/hal-attention-pooling/blob/main/train.py): `train.py`
- **Model Checkpoint**

### Inference

- [Inference Pipeline](https://github.com/alisakour/hal-attention-pooling/blob/main/inference.py): `inference.py`
- [Sentiment and Attention](https://github.com/alisakour/hal-attention-pooling/blob/main/inference.py): `inference.py`

### Other components

- **Researcher**
- **IMDB Dataset**

## Connections

- Dataset Loading → IMDB Dataset: loads (evidence: `data_utils.py`)
- Dataset Loading → Vocabulary and Tokens: builds vocabulary (evidence: `data_utils.py`)
- Training Pipeline → Dataset Loading: loads data (evidence: `train.py`)
- Training Pipeline → HAL Embeddings: builds embeddings (evidence: `train.py`)
- Training Pipeline → Data Loaders: creates loaders (evidence: `train.py`)
- Training Pipeline → Mean Pooling Model: initializes (evidence: `train.py`)
- Training Pipeline → Attention Model: initializes (evidence: `train.py`)
- Training Pipeline → Training and Evaluation: trains and evaluates (evidence: `train.py`)
- Training and Evaluation → Model Checkpoint: saves best weights (evidence: `train.py`)
- Training Pipeline → Metric Plots: plots metrics (evidence: `train.py`)
- Researcher → Training Pipeline: runs training (evidence: `README.md`)
- Researcher → Inference Pipeline: runs inference
- Inference Pipeline → Dataset Loading: loads data (evidence: `inference.py`)
- Inference Pipeline → HAL Embeddings: builds embeddings (evidence: `inference.py`)
- Inference Pipeline → Attention Model: initializes model (evidence: `inference.py`)
- Inference Pipeline → Model Checkpoint: loads weights (evidence: `inference.py`)
- Inference Pipeline → Sentiment and Attention: predicts sentiment (evidence: `inference.py`)
- Attention Model → Sentiment and Attention: returns logits and weights (evidence: `inference.py`)
