Hallucination Entropy Analyzer
Compute token-level entropy and perplexity from top-k probabilities. A heuristic, not a hallucination detector.
Token distribution editor
3 positionsOne block per generated token: the token that was emitted and the top-k candidates with their probabilities.
Metrics
unit: bits| Token | Entropy | Max | Perplexity | Surprisal |
|---|---|---|---|---|
| cat | 0.2747 bits | 1.5850 | 1.2098 | 0.0589 bits |
| sat | 0.4785 bits | 1.5850 | 1.3933 | 0.1203 bits |
| on | 0.1614 bits | 1.5850 | 1.1184 | 0.0291 bits |
Entropy by token
Examples
Uniform four-way split
analyzeTokenDistributions([{ token: "x", probabilities: four 0.25 entries }]).metrics[0]{ entropy: 2, perplexity: 4 }log2(4) equals 2 bits of entropy and 2^2 gives a perplexity of 4.
Rejected probabilities
analyzeTokenDistributions([{ token: "x", probabilities: [{ token: "a", probability: 0.7 }] }]){ valid: false, errors: ["Token 1: probabilities must sum to 1 ..."] }A 0.7 total misses 1 by more than epsilon, so the position is invalid with zero entropy.
About this tool
Hallucination Entropy Analyzer scores top-k token distributions with analyzeTokenDistributions(distributions): each position's Shannon entropy (−Σ p·log2 p), perplexity (2^entropy), and surprise are computed, with cumulative and average entropy rolled up across valid positions.
Validation is strict and deterministic: every probability must be finite within 0–1 and each position must sum to 1 within 1e-9, otherwise the position reports entropy 0 with an explanatory error and the overall result sets valid false.
Example inputs come from scenarioDistributions(kind) — confident, uncertain, or uniform presets with fixed probability tables — so the same kind always analyzes to identical metrics.
How to use this tool
Supply distributions
Pass token positions with probability lists that sum to 1 — e.g. four 0.25 entries for maximum spread.
Read per-token metrics
Use entropy for uncertainty, perplexity for effective vocabulary size, and valid/error for rejected positions.
Compare scenarios
Run scenarioDistributions confident versus uncertain to see low versus high cumulative entropy side by side.
Use cases
Flagging uncertain generations
Treat high per-token entropy as a signal that the model is guessing between alternatives.
Comparing decoding settings
Contrast cumulative entropy across temperatures or prompts with identical distribution shapes.
Teaching entropy basics
Show log2(k) for uniform splits versus 0 for deterministic picks in an interactive demo.
Common mistakes
Mistake:Passing raw logits or unnormalized scores.
Fix:Normalize each position to sum to 1 first — anything else fails validation with a sum-to-1 error.
Mistake:Reading cumulative perplexity as a sum.
Fix:cumulativePerplexity is 2^cumulativeEntropy, not the sum of per-token perplexities.
Frequently asked questions
What does this tool do?
It scores top-k token distributions with analyzeTokenDistributions — per-token entropy, perplexity, and surprise plus cumulative totals — and ships confident, uncertain, and uniform presets via scenarioDistributions.
What do entropy and perplexity mean here?
Entropy is −Σ p·log2 p bits (2 for a uniform four-way split, 0 for a certain token) and perplexity is 2^entropy, the effective number of live alternatives.
Is my model output uploaded or stored?
No. Distribution math and validation run fully client-side.
Why was my distribution rejected?
Every probability must be finite within 0–1 and each position must sum to 1 within 1e-9 — otherwise the position is invalid with a sum-to-1 error, and an empty list is always invalid.
Related guides
References & standards
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.gitattributes Generator
Build .gitattributes rules for line endings, Git LFS, GitHub linguist marks and merge drivers — with a one-line explanation for every rule.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
A/B Test Sample Size Calculator
Compute required sample size per variant and test duration from baseline conversion rate, minimum detectable effect, alpha and power.
ABA Routing Number Validator
Validate 9-digit US ABA routing numbers with 3-7-1 Mod-10 breakdown.