💬 Chatbot Intent Classifier — TF-IDF Similarity Live
Watch a real TF-IDF vectorizer and cosine-similarity matcher score an incoming synthetic user message against a bank of intent templates, live-ranking the best-matching intent as you type.
About this simulation
This simulator runs a genuine TF-IDF (term-frequency, inverse-document-frequency) vectorizer and cosine-similarity matcher entirely in the browser — the same family of algorithm that powers lightweight, explainable chatbot intent routing before (or alongside) a neural model. Every intent template — "check order status", "request refund", "reset my password" and so on — is treated as a document; the corpus vocabulary and IDF weights are recomputed live from those documents. When you type a message or let the synthetic message stream play, the message is tokenized, weighted against the same IDF table, and compared to every intent vector with real dot products and vector norms.
The main panel shows three live views: a ranked bar chart of cosine-similarity scores across all intents, a 2D PCA projection of every intent vector and the current query vector (computed with real mean-centering, covariance and power-iteration eigenvectors — not a fixed layout), and a per-term contribution chart that breaks down exactly which shared words drove the winning match. The confidence gap between the top two intents is a genuine measure of how unambiguous the match is: a small gap means the message is genuinely ambiguous between two templates, not a rendering artifact.
Frequently asked questions
Is the TF-IDF math actually computed, or is it a pre-baked demo?
It is computed live. Tokenization, term-document frequency counts, the smoothed IDF formula ln((1+N)/(1+df))+1, and L2-normalized TF-IDF vectors are all built from whatever intent templates currently exist in the corpus, including any you add yourself.
How is the vector-space plot generated?
Every intent's TF-IDF vector (one dimension per vocabulary term) is mean-centered, and the top two eigenvectors of the resulting covariance matrix are found with power iteration and deflation — a standard, real implementation of Principal Component Analysis. The 2D positions are the projections of each high-dimensional vector onto those two eigenvectors.
Why does an unfamiliar message sometimes get a low confidence score for every intent?
Cosine similarity is bounded and depends entirely on shared vocabulary. If a typed message shares almost no words with any intent's example utterances, every similarity score will be low and the "2nd-best gap" will shrink — a faithful signal that the classifier is unsure, exactly as a production TF-IDF baseline would behave.
What happens when I add a new intent template?
The vocabulary and document-frequency counts are rebuilt across all intents (including the new one), which changes every existing intent's IDF weights slightly. All vectors, the PCA projection and the current query's similarity scores are then recomputed against the new corpus.
Watch a real TF-IDF vectorizer and cosine-similarity matcher score an incoming synthetic user message against a bank of intent templates, live-ranking the best-matching intent as you type.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install