Mixture of Experts (MoE) Deep Dive
A sparse architecture that scales parameter count without proportionally scaling compute. The key idea: not every parameter needs to fire for every token.
How MoE routing works
hidden state
learned gate network
each expert (softmax)
Top-k selection (k=2 typical)
MoE architecture overview
Advantages
Failure modes
| Model | Total params | Active params | Experts | Active per token |
|---|---|---|---|---|
| Mixtral 8x7B | 46.7B | ~12.9B | 8 | 2 |
| Mixtral 8x22B | 141B | ~39B | 8 | 2 |
| Switch Transformer | 1.6T | ~7B | 2048 | 1 |
| GPT-4 (unverified leak) | ~1.8T? | ~220B? | 16? | 2? |
Knowledge Graphs + LLMs
When structured knowledge complements unstructured text retrieval — and when it doesn't.
Interactive: Knowledge Graph Structure
Nodes are entities. Edges are typed relationships. Click "New Layout" to rearrange.
When to use what
| Need | Best tool |
|---|---|
| "Find docs about X" | Vector retrieval (RAG) |
| "What owns what?" | Knowledge graph |
| "Who reports to whom?" | Knowledge graph |
| "Similar products to X" | Vector retrieval |
| "All entities related to X within 3 hops" | Knowledge graph |
| "Semantic search over docs" | Vector retrieval |
| "Complex multi-hop reasoning" | Both (graph + RAG) |
Many strong production systems use both. Vector retrieval for broad evidence discovery, knowledge graphs for entity-grounded logic and traceability. The choice is empirical, not ideological.
Adaptive Softmax
How to make the output layer efficient when your vocabulary has 128,000+ tokens — most of which are rare.
The problem: standard softmax is expensive
The output layer maps hidden_dim -> vocab_size. For a model with 128K vocabulary and 4096-dim hidden state, that's a 4096 x 128,256 matrix multiplication at every decoding step for every token. Most of that compute goes to rare tokens that almost never get selected. Note: modern LLMs (GPT-4, LLaMA 3, Claude) compute the full softmax rather than using adaptive softmax — the technique below is historically important and still relevant for resource-constrained settings.
Token frequency follows a power law. The top 1% of tokens account for ~80% of usage.
The solution: hierarchical clusters
Adaptive softmax groups the vocabulary into clusters by frequency. Frequent tokens get the full-dimensional projection. Rare tokens use a cheaper, lower-dimensional projection.
"the", "a", "is", "and" ... Computed every step. These cover ~80% of all outputs.
Less common words. Only compute full softmax over these if Cluster 1 doesn't contain the answer.
Rare tokens, special characters. Rarely needed. Cheapest to compute when invoked.
Claude vs GPT Ecosystem Comparison
Both are frontier systems. The differences are in packaging, defaults, and ecosystem ergonomics — not "which is better."
| Dimension | Claude (Anthropic) | GPT (OpenAI) | What matters in practice |
|---|---|---|---|
| Context window | up to 1M tokens (Opus 4.x / Sonnet 4.6) | up to 400K (GPT-5 Pro) | Long context is a capability, not a default mode. Retrieval often beats cramming. |
| Tool use | Function calling, MCP | Function calling, MCP, GPT Actions | MCP is now a cross-vendor standard (Anthropic, OpenAI, Google, Microsoft). |
| Reasoning | Extended thinking (visible chain) | GPT-5 series reasoning (5.2 / 5.5) | Different approaches to "slow thinking." Evaluate on your specific task. |
| Safety approach | Constitutional AI, RLHF | RLHF, system prompt controls | Both invest heavily. Specific refusal behavior differs by model version. |
| API ergonomics | Messages API, streaming | Chat Completions / Responses API | Very similar patterns. Switching cost is low. |
| Ecosystem | Claude Code, Artifacts, MCP | ChatGPT, GPTs, Actions, Codex | OpenAI has broader consumer reach. Anthropic focuses on developer/enterprise. |
Stay current-aware and avoid hard-coding assumptions that change by release. The right comparison is always empirical: benchmark the candidate models on your workload, your prompts, and your latency budget instead of relying on brand-level folklore. Strong candidates separate research novelty from deployability.
Hyperparameters Beyond Learning Rate
Every knob the engineer sets (rather than the model learns) is a hyperparameter. Good teams treat them as system design, not afterthoughts.
Training hyperparameters
Serving & RAG hyperparameters
Interactive: Learning rate schedule
Adjust warmup fraction and decay type to see how the learning rate changes over training.
Bias & Fairness in LLM Outputs
Making bias concrete and measurable — not a slogan, but an engineering process.
Where bias enters
Internet text reflects historical biases. Underrepresentation of minority perspectives. Toxic content patterns.
Attention patterns may amplify high-frequency patterns. Rare groups get less representation in learned features.
Annotator demographics and guidelines shape what the model considers "good." Can both fix and introduce biases.
System prompts, retrieval corpus, user interface framing all shape how biases manifest in practice.
Engineering responses
Interpretability Challenges
Understanding why a model produced a specific output is one of the hardest open problems in AI. Here's what works, what doesn't, and why attention maps can mislead.
Attention visualization: useful but misleading
Attention weights show what tokens the model "looked at," but NOT what it learned from them. High attention does not mean high influence on the output. The value vectors determine what information actually flows through.
Common interpretability pitfalls
Privacy in LLM Deployment
Privacy is not a feature to add later — it's an architectural constraint that shapes the entire system from day one.
Privacy threat model for LLM systems
sensitive prompt
confidential docs
combined context
leak PII/secrets
everything
Attack surfaces
Controls
Common Deployment Bottlenecks
The things teams consistently underestimate. Click to mark items you've addressed in your system.
Operational
Eval sets go stale. New edge cases emerge. Maintaining quality benchmarks is ongoing work, not a one-time setup.
Prompts are code. They need versioning, testing, and regression checks. A prompt that works on GPT-4 may fail on GPT-4o.
Model updates change behavior. You need automated regression detection and rollback capability.
Can you trace a bad output back to its retrieval results, prompt, model version, and user context? If not, debugging is guesswork.
Quality & Governance
When retrieval, tools, and model all have different permission models, ensuring the response respects all of them is hard.
P50 looks great; P99 is terrible. Long inputs, complex tool calls, and cold caches create unpredictable spikes.
Failures span retrieval + permissions + model + tools. No single team owns the whole path. Distributed debugging across teams is the bottleneck.
Compute cost is obvious. The hidden costs: evaluation compute, data labeling, prompt engineering time, incident response for AI-specific failures.
When the model fails, where does the user go? Graceful degradation and human handoff are features, not afterthoughts.