Demos, combined
Demos, Combined
A couple of weeks ago I put together a small set of classical NLP demos, mostly for teaching. The idea was simple: before reaching for a large language model, it helps to see how computers handled text when all they had was rules and counting. That set has since grown a sibling covering classical machine learning, and the two now live together on a single demos page.
What’s in there
The NLP collection covers the old guard: regular expressions, a faithful recreation of ELIZA (1966, still unsettlingly good at deflecting questions), tokenization, TF-IDF, BM25, naive Bayes and a couple of ways of turning words into vectors, ending with word2vec.
The machine learning collection starts with fitting a straight line and works its way up through gradient descent, logistic regression, nearest neighbours, decision trees, random forests, gradient boosting and a small neural network playground. It finishes with k-means, PCA and self-organising maps. There is also a demo on evaluating classifiers, which is less glamorous but probably the most useful of the lot. Set the disease prevalence to 1% and watch a perfectly respectable test produce mostly false alarms.
Every demo is interactive: add points, drag them about, move sliders, and the model updates as you go. Each comes with a short explanation and references for anyone who wants the actual maths. Many of the examples are borrowed from medicine (blood pressure, thyroid function, electrolytes), but none of the data is real, and the audience is meant to be broader than medical students.
A few principles
- Everything runs in the browser. Nothing you type or draw is sent anywhere, and the whole thing is plain static files.
- The maths should be right. The models were checked against scikit-learn (and the stemmer against NLTK), which caught more than one off-by-something along the way.
- Nothing should flash. Some of the training animations update very quickly, so they are smoothed and kept well below the accessibility limit for flashing content. Watching a self-organising map unfold is fun; a strobe light is not.
One page
Having the NLP and ML demos on separate pages was starting to feel silly, especially once demos began referring to each other. The word2vec demo uses PCA, for instance, which now has its own demo. So everything is on one page, with a search bar, a filter for each collection and links between related demos. Hover over a highlighted term to see what the other demo is about, and click to go there. Each demo only loads when it is opened, so the page stays light however many get added. Old links to the separate pages still work.
What’s next
Probably something a bit further from machine learning: how a message actually gets across a network, what a TCP handshake looks like, and why changing a single character in a password changes its hash beyond all recognition. Or I may just keep adding demos until the sidebar needs its own sidebar.