Spam filter
A spam filter, or spam classifier in machine-learning terms, reads a message and answers one question: is this spam? The one you train here answers spam or not spam, and says how sure it is.
It is not a small problem. People in the US reported losing $470 million to scams that started with a text message in 2024, five times the 2020 figure, according to the Federal Trade Commission.
A rule written by hand catches some spam and misses the rest. In his 2002 essay A Plan for Spam, Paul Graham found that looking for the single word "click" caught 79.7 percent of his spam but also flagged 1.2 percent of his real mail, while a filter that learned from examples of each missed "less than 5 per 1000 spams, with 0 false positives." Learning from examples became the standard approach.
The model on this page learns from examples too. It is a small GPT, the same kind of model as the ones behind chat assistants, trained from scratch in your browser, and it reads each message one character at a time, so it can pick up whatever gives spam away (the prize wording, the capital letters, the short codes to text back) without anyone listing it.
Training
Training is a guessing game, played tens of thousands of times. The model reads a message and guesses its label. Then it is shown the real label, and every one of its internal numbers, its parameters, is nudged slightly toward the answer that would have been right. Each step covers 32 messages and a run is 1,500 steps, so it makes 48,000 guesses over 840 training messages, seeing each one about 57 times.
Only the label is graded. The model reads the whole message, but it is marked only on the answer that comes after it, never on predicting the message itself, so all of its learning goes into the one judgment you want. In our measurement on a Mac's graphics chip, a full run took about four minutes (257 seconds), live scoring included. Without WebGPU it trains on the processor instead, which is slower.
Held-out score
Before training starts, 240 messages, 120 spam and 120 real, are set aside, and the model never trains on them. While it trains, the live score is measured on those messages, and at the end it is scored on all of them. That is the honest number: a model can memorize the messages it practiced on, but it cannot memorize ones it has never seen. The set-aside messages were also checked for near copies, so a message that differs from a training message by only a word or a number cannot slip in as a free point.
On our own engine, with exactly this setup, it scores 95 percent (measured twice, 228 of 240 held-out messages both times, 95% confidence 91 to 97; it catches about 93 percent of spam and correctly passes about 97 percent of real messages).
Rule versus model
Classic text scams have a visible tell: they ask you to text a short code, call a premium number or claim a cash prize, so they are full of digits. The best one-line rule we found builds on it: call a message spam when it holds three or more digits. Tuned on the training messages, then scored once on the same 240 held-out messages as the model, the rule gets 92.1 percent right (221 of 240): it catches 103 of the 120 spam messages and wrongly flags 2 of the 120 real ones. The model gets 95. Allowing for the sampling error of a 240-message test, the two ranges overlap, so on this data the model's lead over the rule is small.
Compared message by message, the model's extra points come almost entirely from scams with few or no digits, which the rule cannot see. In three further runs on all 420 examples of each kind, each starting from different random numbers, it got 9 to 11 of the rule's 19 mistakes right while getting 4 to 6 wrong that the rule got right. It finds the digit cue itself, and fast: trained on only 10 examples of each kind, it already scored 84 to 91 percent. We measured how the score grows with the number of examples, on this task and two others, in How many examples does a text classifier need?.
Balanced classes
Spam-classifier tutorials often report 97 to 99 percent accuracy, and on this dataset that number is less impressive than it looks. Of the SMS Spam Collection's 5,574 messages, 4,827 are real and only 747 are spam, so a model that answers not spam every time is already right 86.6 percent of the time. Nanotech trains and tests on equal numbers of each kind, 420 of each to train on and 120 of each held out, so always giving the same answer scores 50 percent, and every point above that is something the model learned. In our measurements, balancing the two kinds also raised how much of the spam it catches by about five points, more than any change we tried to the model itself.
Confidence
Every answer comes with how sure the model is, and that is what makes a model this small usable. Measured on the held-out messages, it is right about 97 percent of the time on the three quarters of messages it is most sure about, against 95 percent overall, so its mistakes concentrate in the quarter it is least sure about, which is where a person's attention is best spent. Treat the number as a ranking rather than a promise: 90 percent sure does not mean wrong exactly one time in ten.
SMS Spam Collection
The messages are real texts from the SMS Spam Collection, published in 2011 by Tiago A. Almeida, José María Gómez Hidalgo and Akebo Yamakami under the CC BY 4.0 license. 425 of its 747 spam messages were collected by hand from Grumbletext, a UK forum where people post the spam texts they receive, and 3,375 of its 4,827 real ones come from a corpus of texts gathered at the National University of Singapore, mostly from students. In spam research a real message is called ham; the model here answers not spam, which says the same thing in plain words.
Your own messages
A filter trained on messages collected for a 2011 study knows the scams of that era. Graham's advice from 2002 still applies: "each user should have his own per-word probabilities based on the actual mail he receives." To catch what your own inbox, comment section or contact form actually gets, train a text classifier on your own examples: paste messages you have already sorted, each labeled spam or not spam, and the same kind of model learns your mix instead.
Questions
Is spam detection supervised or unsupervised learning?
Supervised. The model learns from messages that already carry the right answer, spam or not spam, and training is the work of making its guesses match those answers. Methods that learn without any labels exist, but a spam filter like this one is supervised.
How is this different from a Naive Bayes spam filter?
A Naive Bayes filter, the kind Paul Graham described, counts how often each word appears in spam and in real mail and combines those counts into a probability. It is fast, simple and strong on this kind of data, which is why most tutorials use it. We measured both on this page's messages: with all 420 examples of each kind, Naive Bayes over words got 95.8 percent of the held-out messages right and this model 94.3 on average over three runs, a tie within the margin of a 240-message test. The model here learns differently: it is a neural network that reads the message in order, one character at a time, trained the same way large language models are, by guessing and being corrected. Watching it learn is the point: it shows you, step by step, how a model like that picks up a judgment from examples.
Can it check a text message I just received?
You can paste one in once it is trained and see what it says, but treat the answer as a lesson, not a verdict: it learned from messages collected for a 2011 study, and today's scams look different. If a message asks you to click a link or to pay, check with the sender through a channel you already trust.
Do my messages leave my browser?
No. The examples it trains on come with the page, and the model trains and answers inside your browser. Whatever you type to test it is read by the model in your browser and sent nowhere. The site's analytics count page visits and a few steps like starting a training run, never the text you type.
Can I keep the trained model?
Yes. It is saved in your browser automatically, about every 45 seconds while it trains and whenever it pauses or finishes, and you can download it as a .nanotech file that opens again in the studio, on this device or another. There is no export to other formats, so it runs here rather than in your own code.
Is it free?
Yes. It trains right in your browser, so there is no server doing the work and nothing to meter, and you do not need an account.