›
🗺 Roadmap Mindmap & Architecture Flow 11 Stages
← Main Roadmap 🗺 Interactive Graph 📑 11-Stage Walkthrough ⚡ Live Sim
✦ CHARAN AI ARCHITECTURE & MINDMAP HUB

End-to-End LLM Lifecycle:
Interactive Mindmap & 11-Stage Flow

Interactive node mindmap meets deep architectural walkthrough. Explore the full progression from raw prompt ingestion through BPE tokenization, embedding geometry, multi-head attention, autoregressive prediction, and formatted delivery.

🧪 Interactive Sentence Testbench
Scroll to zoom · Drag to pan · Click any node to jump to its deep-dive or lesson page
Click to inspect →
01 User Input 02 Tokenization 03 Token Embedding 04 Positional Info 05 Transformer Engine 06 Attention Mechanism 07 Context Processing 08 Next-Token Prediction 09 Token Generation 10 Detokenization 11 Output Processing
STAGE 01 · PROMPT INPUT LAYER

User Input & Context Assembly

Capturing text, instructions, multi-turn history, documents, and modalities before model ingestion
PROMPT INGESTION
Payload Assembly Simulator JSON Payload
// Assembled Context Payload:
{
  "system": "You are an expert AI researcher explaining neural networks.",
  "history": [{"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi Charan!"}],
  "user_prompt": "Charan planted a new thought in Advaitha's head.",
  "retrieved_context": "[RAG chunk: Cognitive architectures 2025]"
}

Every interaction begins as unstructured data. The application layer compiles the system instructions, conversation history, retrieved knowledge (RAG), and multimodal attachments (images, audio, files) into a unified context packet. Input validation and prompt injection defenses sanitize this payload before handing off to the tokenizer.

STAGE 02 · TEXT PROCESSING LAYER

Tokenization & Vocabulary Mapping

Splitting raw string characters into discrete subword integer tokens (BPE / SentencePiece)
TEXT TO INTEGERS
BPE Tokenizer Decomposition 9 Tokens
Vocabulary Lookup: $T = [t_1, t_2, \dots, t_N], \quad t_i \in \{0, 1, \dots, |V|-1\}$
Special Tokens: $\langle|\text{bos}|\rangle, \langle|\text{eos}|\rangle, \langle|\text{pad}|\rangle, \langle|\text{im\_start}|\rangle$

Computers cannot process raw characters directly. The tokenizer applies Byte Pair Encoding (BPE) or WordPiece to split words into frequent subword units, avoiding out-of-vocabulary errors while preserving morphologic stems. Each token is assigned a unique integer ID from a fixed vocabulary (e.g. 32,000 to 128,000 unique tokens).

STAGE 03 · NUMERICAL REPRESENTATION LAYER

Token Embedding Matrix Lookup

Mapping discrete integer IDs to dense high-dimensional semantic vectors in geometric space
INTEGERS TO VECTORS
Embedding Matrix Lookup ($W_E \in \mathbb{R}^{|V| \times d}$) $d_{model} = 4096$
// Vector Lookup: ID 4125 ("Charan") → [0.42, -0.19, 0.88, ..., 0.05]
Embedding Table Lookup: $\mathbf{x}_i = W_E[t_i], \quad \mathbf{x}_i \in \mathbb{R}^{d_{model}}$
Cosine Similarity: $\cos(\mathbf{u}, \mathbf{v}) = \frac{\mathbf{u} \cdot \mathbf{v}}{\|\mathbf{u}\| \|\mathbf{v}\|}$

Each integer ID acts as a row index into a massive learned weight matrix $W_E$. The lookup converts a discrete ID into a rich vector of floating-point numbers (e.g. 768 to 4,096 dimensions). Tokens with similar grammatical roles or semantic meanings are placed close together in this high-dimensional vector space.

STAGE 04 · SEQUENCE UNDERSTANDING LAYER

Positional Encoding & RoPE

Injecting word order awareness into permutation-invariant self-attention matrices
INJECT ORDER
Positional Signal Injection Sinusoids / RoPE Rotation
// Position 0 ("Charan"): Angle θ₀ = 0° → Vector unaltered
// Position 1 ("planted"): Angle θ₁ = 15° → Rotated in 2D slices
// Position 6 ("Advaitha"): Angle θ₆ = 90° → Rotated by relative Δpos
Sinusoidal: $PE_{(pos, 2i)} = \sin\left(\frac{pos}{10000^{2i/d}}\right), \quad PE_{(pos, 2i+1)} = \cos\left(\frac{pos}{10000^{2i/d}}\right)$
Rotary (RoPE): $\mathbf{q}_m = \mathbf{R}_{\Theta, m}^d \mathbf{W}_q \mathbf{x}_m, \quad \mathbf{k}_n = \mathbf{R}_{\Theta, n}^d \mathbf{W}_k \mathbf{x}_n \implies \mathbf{q}_m^T \mathbf{k}_n = f(\mathbf{x}_m, \mathbf{x}_n, m-n)$

Self-attention has no innate sense of sequence: "Charan planted a thought in Advaitha" looks identical to "Advaitha planted a thought in Charan". Positional information solves this by either adding sinusoidal/learned position vectors or multiplying by 2D rotational transformation matrices (RoPE in LLaMA / Mistral / DeepSeek).

STAGE 05 · CORE PROCESSING ENGINE

Transformer Architecture & Blocks

Passing position-aware tokens through deep stacked residual blocks with LayerNorm & FFNs
NEURAL HIGHWAY
Transformer Layer Forward Pass $N = 32 \text{ Layers}$
Input: $\mathbf{X}_0 \in \mathbb{R}^{T \times d}$ (Embeddings + Pos)
  ↳ RMSNorm($\mathbf{X}_l$) → Multi-Head Attention → + Residual Stream ($\mathbf{X}_l + \text{MHA}$)
  ↳ RMSNorm($\mathbf{X}'_l$) → Feed-Forward (SwiGLU / MLP) → + Residual Stream ($\mathbf{X}'_l + \text{FFN}$)
Output: $\mathbf{X}_{l+1}$ passed to Layer $l+1 \dots$
Residual Highway: $\mathbf{x}_{l+1} = \mathbf{x}_l + \text{MHA}(\text{LN}(\mathbf{x}_l)) + \text{FFN}(\text{LN}(\mathbf{x}'_l))$
Feed-Forward Network: $\text{FFN}(\mathbf{x}) = \text{Swish}(\mathbf{x} W_{gate}) \odot (\mathbf{x} W_{up}) W_{down}$

Modern LLMs (like GPT-4, Claude, LLaMA) are decoder-only autoregressive Transformers. They stack 32 to 128 identical Transformer blocks. The residual stream acts as an information superhighway that allows gradients to flow directly through hundreds of layers without vanishing.

STAGE 06 · CONTEXT UNDERSTANDING LAYER

Multi-Head Self-Attention (QKV)

Querying, key matching, softmax weighting, and value aggregation across all tokens
DYNAMIC FOCUS
Attention Weight Matrix $Q \cdot K^T / \sqrt{d_k}$
Token "planted" attending across sequence:
  → "Charan": 0.38 (Who planted?)
  → "thought": 0.42 (Planted what?)
  → "Advaitha": 0.16 (Planted in whom?)
  → "a" / "new": 0.04 (Modifiers)
Scaled Dot-Product Attention: $\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{Q K^T}{\sqrt{d_k}} + M\right) V$
Multi-Head: $\text{MHA}(Q, K, V) = \text{Concat}(\text{head}_1, \dots, \text{head}_h) W^O$

For every token, the network projects three vectors: Query ($Q$) (what am I looking for?), Key ($K$) (what do I offer?), and Value ($V$) (what information do I contain?). The dot product of $Q$ and $K$ measures similarity. After scaling and applying a causal mask $M$, a softmax produces attention weights that blend the $V$ vectors into a contextualized state.

STAGE 07 · UNDERSTANDING & INTEGRATION

Context Processing & Reasoning

Synthesizing instructions, conversation history, retrieved documents, and token budget
CONTEXT SYNTHESIS
Context Window Allocation Budget: 128K Tokens
🟦 System (15%)   🟪 History (25%)   🟩 RAG Docs (35%)   🟨 Prompt (10%)   ⬛ Headroom (15%)
Effective Context Limit: $N_{tokens} \le N_{ctx} \quad (8\text{K} \to 128\text{K} \to 1\text{M}+)$
Context Compression: $\text{KV\_Cache}_{t} = [\text{KV\_Cache}_{t-1}, K_t, V_t]$

The model synthesizes the entire sequence representation into an integrated semantic state. It resolves coreferences (e.g. "head" belongs to "Advaitha"), follows user directives, disambiguates complex constraints, and retains facts across lengthy multi-turn conversations.

STAGE 08 · PREDICTION & PROBABILITY LAYER

Next-Token Prediction & Sampling

Unembedding final hidden state into logits, applying Softmax, Temperature, Top-K and Top-P
PROBABILITY RANKING
Candidate Token Probabilities $T = 0.7, \text{ Top-P} = 0.9$
"It" (selected) 68.4%
"This" 18.2%
"The" 8.1%
Logits Generation: $\mathbf{z} = \mathbf{h}_{final} W_U, \quad \mathbf{z} \in \mathbb{R}^{|V|}$
Softmax with Temperature: $P(t_{next} = w_i) = \frac{\exp(z_i / T)}{\sum_{j=1}^{|V|} \exp(z_j / T)}$

The final hidden vector $\mathbf{h}_{final}$ at the last sequence position is multiplied by the unembedding matrix $W_U$ to generate raw scores (logits) for all tokens in the vocabulary. Softmax normalizes them into a probability distribution. Decoding strategies (Greedy, Temperature, Top-K, Top-P Nucleus) select the single next winner.

STAGE 09 · RESPONSE GENERATION LOOP

Autoregressive Generation Loop

Appending newly predicted tokens back into context until stop-token or maximum length is reached
AUTOREGRESSIVE LOOP
Streaming Generation Stream KV Cache Active
Generated: "It was an intriguing moment of inspiration."
Tokens: [It] → [ was] → [ an] → [ int] → [rigu] → [ing] → [ moment] → [ of] → [ inspiration] → [.] → [<|eos|>]
Autoregressive Step: $\mathbf{x}_{1:t+1} = [\mathbf{x}_{1:t}, \quad \text{sampled\_token}_{t+1}]$
Termination Condition: $\text{sampled\_token} == \langle|\text{eos}|\rangle \quad \lor \quad t \ge \text{max\_tokens}$

Generation is autoregressive: the model generates one token at a time. The newly predicted token is appended to the input sequence, and the full forward pass repeats. KV caching stores prior key-value attention vectors to avoid redundant computation, speeding up inference by orders of magnitude.

STAGE 10 · TEXT RECONSTRUCTION LAYER

Detokenization & Text Assembly

Converting token integer IDs back to raw UTF-8 bytes, merging subwords, and restoring whitespace
INTEGERS TO TEXT
Subword Merging & Decoding ID → UTF-8
Token IDs: [2038, 374, 281, 1928, 411, 278, 1823]
  ↳ Byte Lookup: ["It", " was", " an", " int", "rigu", "ing", " thought"]
  ↳ Subword Stitch: "int" + "rigu" + "ing" → "intriguing"
  ↳ Final String: "It was an intriguing thought"
Detokenizer Mapping: $S = \text{Decode}(T), \quad T \subset \mathbb{N} \to \text{UTF-8 String}$
Control Token Strip: $S_{clean} = \text{regex\_strip}(S, \quad \text{pattern}=\langle|.*|\rangle)$

The reverse of tokenization. As token IDs emerge from the sampling loop, the detokenizer maps each integer back to its corresponding character or byte chunk. Subword fragments are stitched together, unicode byte boundaries are aligned, leading whitespace flags (e.g. Ġ or ) are turned into spaces, and control tokens are stripped.

STAGE 11 · RESPONSE DELIVERY & ACTION LAYER

Output Processing & Tool Delivery

Markdown rendering, structured JSON validation, safety guardrails, and tool execution loops
DELIVERY & ACTION
Delivered Response Preview Markdown / Tool Call
AI Assistant Response:
Charan's metaphor of "planting a thought" highlights how concepts spread through language, attention, and cognitive reinforcement.
✓ Guardrail Checked   ✓ Markdown Highlighted   ✓ Tool Call Executed
Structured Validation: $\text{Pydantic}(\text{Output}) \to \text{Schema Verified}$
Agent Tool Call: $\text{If } \text{tool\_call} \implies \text{Execute}(\text{args}) \to \text{Feed back to Stage 1}$

The final reconstructed string passes through the application safety and display layers. Output guardrails check for toxic content or hallucinations. If the model generated a structured tool call (e.g. running code or calling a database), the agent system intercepts it, executes the action, and loops the result back into Stage 1.