AI and rules
Artificial intelligence (AI) is the broad goal of getting machines to do tasks that seem to need intelligence, such as understanding speech, recognising faces or sorting email. Our task here: keep spam, unwanted junk email, out of the inbox.
One way is to write the rules by hand. A person decides: if an email contains "free money", put it in the spam folder. The program follows the rule exactly, so "free money for you" goes to spam.
Spammers change their words. "free prize inside" does not contain "free money", so the rule lets it into the inbox: wrong. Someone would have to keep writing new rules, for ever, to keep up.
Learning from examples
Machine learning (ML) is one way to do AI. Instead of writing the rules ourselves, we give the computer examples with the right answers, and a learning program finds the patterns itself.
The examples are the training data. Each one is an email plus its label, the right answer: spam or not spam. People added the labels. Real filters learn from many thousands of emails; we use six.
Training runs a learning program over every example. Ours scores words: +1 for each spam email a word appears in, −1 for each normal one. What it keeps, the word scores, is the model: patterns, not the emails.
A new email the model has never seen: "free prize inside". It adds up its word scores: free +2, prize +2, inside 0 (never seen). The total, +4, is above zero, so its prediction is spam.
"notes from lunch" scores notes −2, from 0, lunch −1: total −3, so it goes to the inbox. A model can still be wrong. When people mark a mistake, it becomes a new labelled example and the model is trained again.
Kinds of learning
Supervised learning learns from labelled examples, like our spam filter. Unsupervised learning gets no labels and finds groups of similar things. Reinforcement learning tries actions and learns from rewards and penalties, like points in a game.
Today's generative AI, such as chatbots, uses far bigger models trained on huge amounts of text. Given "See you at", a language model predicts a likely next word, "lunch", adds it, and repeats: "tomorrow". That is how it writes.
What happens
;; step 1/10 · ai
AI the goal: machines doing tasks needing intelligence
examples understanding speech, recognising faces,
playing games, translating, sorting email
our task sort each new email:
spam unwanted junk -> spam folder
not spam normal mail -> inbox
The word-score learner is a real, runnable program, but a toy. Real spam filters weigh words by probability (a method called naive Bayes) and learn from thousands of emails. Language models really predict tokens (whole words or pieces of words) and choose among many likely ones. The words in the last step are an illustration, not the output of a real model.