Skip to content
mentoor

Topic 2 of 4 · 4 min read

Hand-written rules versus learned patterns

Goal: Tell whether a described system follows hand-written rules or learned patterns, and predict how each fails on a new case.

Some software follows rules a person wrote. Other software learns a pattern from examples. The two fail in different ways, so you must know which one you have.

Check yourself · 1 of 3

A program flags a message as spam only if it contains one of 40 phrases that a developer typed in. What kind of system is it?

Choose one answer

Why it matters

When a system makes a mistake, the fix depends on its kind. A rule-based system has a rule you can find and change. A learned system has no single rule to point at. Its behaviour comes from the examples it saw. If you expect a learned system to behave like a rulebook, you will be surprised.

How each one works

Rules. A programmer writes: "If the email contains the words 'free money', mark it as spam." The system does exactly that, every time. It is predictable and easy to explain. But it only knows what the programmer thought of.

Learned patterns. You give a system many emails already labelled "spam" or "not spam". It finds what the spam ones have in common: odd links, urgent tone, strange sender addresses, and thousands of small clues no one listed. Then it scores new emails by how much they look like the spam it has seen.

Why learning wins on messy problems

Spammers change their words every week. A rulebook needs a person to notice and add a rule each time. A learned filter can be retrained on fresh examples. For tasks like spotting spam, reading handwriting or recognising a voice, the rules are too many and too fuzzy to write down. Examples are easier to collect than rules.

Before and after

Before: "The filter is smart, so it will catch all spam." This treats it like a perfect rulebook.

After: "The filter learned from past spam. It will catch most spam that looks like what it saw. A brand-new trick, or a real invoice that looks odd, may be misjudged." This treats it as a pattern matcher with a score.

How each one fails

  • Rules fail on the case no one thought of. A rule for "free money" misses "fr3e m0ney". It fails loudly and in the same way each time.
  • Learned systems fail on cases unlike their examples. A spam filter trained on English mail may do badly on mixed-language mail. It fails quietly. It still returns an answer and sounds sure.
  • Learned systems copy the flaws in their examples. If the training mail was labelled by someone who marked all newsletters as spam, the filter will too.

A chatbot works the same way at a much larger size. It learned patterns from huge amounts of text. That is why it can write well on common topics and still invent an answer on a rare one.

Ask two questions of any system: who wrote the behaviour, a person or the data? And what does it do when it sees something new?

Examples

Two ways to catch spam

Rules: block any message with the phrase "you have won". Easy to read, easy to dodge ("y0u have w0n").

Learned: train on 100,000 messages marked spam or not. It notices dozens of weak signals together, so a reworded scam can still score high. It may also flag a real prize notice from a competition you entered.

What fails on a new case

A bank adds a new payment type. A rule-based checker has no rule for it and lets it through or blocks it by default. A learned checker has never seen it and gives a score based on whatever it most resembles, which may be wrong with no warning.

Key points

  • A rule-based system does exactly what a person wrote, and nothing more.
  • A learned system finds patterns in labelled examples and scores new cases by how similar they look.
  • Rules are predictable but miss any case their author did not think of.
  • Learned systems handle messy tasks like spam or speech, but can fail quietly on cases unlike their examples.
  • A learned system can inherit the mistakes and bias of its training examples.
  • To fix a rule you edit the rule; to fix a learned system you change the data or retrain it.

Common mistakes

  • Expecting a learned system to follow a clear rule you can look up.
  • Trusting a confident score as proof, when the case may be unlike the training examples.
  • Assuming a learned system is neutral when its examples came from human labels.
  • Believing that more rules always fix a learned system, instead of better or fresher examples.

Check yourself · 2 of 3

A rule-based system meets a case its author never imagined. What usually happens?

Choose one answer

Check yourself · 3 of 3

A learned spam filter trained on English mail starts missing scams written in Portuguese. What is the best explanation?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic