# malleswarikosuri/transformer-forward-pass-explorer architecture

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

- Interactive diagram: https://gitdiagram.com/malleswarikosuri/transformer-forward-pass-explorer
- Repository: https://github.com/malleswarikosuri/transformer-forward-pass-explorer

## Overview

This is a small Streamlit dashboard for exploring a fixed-weight Transformer forward pass, not a trained language model. A user enters text and sets a temperature; the dashboard calls the core simulator, which tokenizes the prompt, builds representations, computes causal attention and feed-forward outputs, then produces next-token probabilities. The dashboard presents token IDs, numeric representations, an attention heatmap, probability rankings, and a sampled token. The core source shows the computation; README capability descriptions supplement the sampled UI excerpt.

Main entry points: [`app.py`](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/app.py) (Results + Visualizations), [`transformer_core.py`](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py) (Tokenizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard"]
  node_dashboard["Streamlit Dashboard<br/>[app.py]"]
  node_visualization["Results + Visualizations<br/>[app.py]"]
end

subgraph group_forward["Transformer Forward Pass"]
  node_tokenizer["Tokenizer"]
  node_representations["Embeddings + Position"]
  node_attention["Causal Attention"]
  node_transformer_block["Residual + Feed Forward"]
end

subgraph group_prediction["Token Prediction"]
  node_logits["Output Logits"]
  node_probabilities["Temperature + Softmax"]
  node_rankings["Top Predictions"]
  node_sampling["Token Sampling"]
end

node_user(("Prompt User"))

node_user -->|"enters prompt"| node_dashboard
node_dashboard -->|"runs forward pass"| node_tokenizer
node_tokenizer -->|"maps token IDs"| node_representations
node_representations -->|"projects Q K V"| node_attention
node_attention -->|"provides attention output"| node_transformer_block
node_transformer_block -->|"projects final state"| node_logits
node_logits -->|"applies temperature"| node_probabilities
node_dashboard -->|"requests top predictions"| node_rankings
node_dashboard -->|"requests sampled token"| node_sampling
node_dashboard -->|"renders results"| node_visualization
node_probabilities -->|"ranks probabilities"| node_rankings
node_probabilities -->|"samples token"| node_sampling
node_tokenizer -->|"displays token IDs"| node_visualization
node_representations -->|"displays numeric vectors"| node_visualization
node_attention -->|"plots attention weights"| node_visualization
node_rankings -->|"displays rankings"| node_visualization
node_sampling -->|"displays sampled token"| node_visualization

click node_dashboard "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/app.py"
click node_tokenizer "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_representations "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_attention "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_transformer_block "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_logits "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_probabilities "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_rankings "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_sampling "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py"
click node_visualization "https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/app.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_dashboard,node_visualization,node_user toneBlue
class node_tokenizer,node_representations,node_attention,node_transformer_block toneAmber
class node_logits,node_probabilities,node_rankings,node_sampling toneMint
```

## Components

### Dashboard

- [Streamlit Dashboard](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/app.py): `app.py`
- [Results + Visualizations](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/app.py): `app.py`

### Transformer Forward Pass

- [Tokenizer](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`
- [Embeddings + Position](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`
- [Causal Attention](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`
- [Residual + Feed Forward](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`

### Token Prediction

- [Output Logits](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`
- [Temperature + Softmax](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`
- [Top Predictions](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`
- [Token Sampling](https://github.com/malleswarikosuri/transformer-forward-pass-explorer/blob/main/transformer_core.py): `transformer_core.py`

### Other components

- **Prompt User**

## Connections

- Prompt User → Streamlit Dashboard: enters prompt (evidence: `app.py`)
- Streamlit Dashboard → Tokenizer: runs forward pass (evidence: `app.py`)
- Tokenizer → Embeddings + Position: maps token IDs (evidence: `transformer_core.py`)
- Embeddings + Position → Causal Attention: projects Q K V (evidence: `transformer_core.py`)
- Causal Attention → Residual + Feed Forward: provides attention output (evidence: `transformer_core.py`)
- Residual + Feed Forward → Output Logits: projects final state (evidence: `transformer_core.py`)
- Output Logits → Temperature + Softmax: applies temperature (evidence: `transformer_core.py`)
- Streamlit Dashboard → Top Predictions: requests top predictions (evidence: `app.py`)
- Streamlit Dashboard → Token Sampling: requests sampled token (evidence: `app.py`)
- Streamlit Dashboard → Results + Visualizations: renders results (evidence: `app.py`)
- Temperature + Softmax → Top Predictions: ranks probabilities (evidence: `transformer_core.py`)
- Temperature + Softmax → Token Sampling: samples token (evidence: `transformer_core.py`)
- Tokenizer → Results + Visualizations: displays token IDs (evidence: `app.py`)
- Embeddings + Position → Results + Visualizations: displays numeric vectors (evidence: `app.py`)
- Causal Attention → Results + Visualizations: plots attention weights (evidence: `app.py`)
- Top Predictions → Results + Visualizations: displays rankings (evidence: `app.py`)
- Token Sampling → Results + Visualizations: displays sampled token (evidence: `app.py`)
