Grade 10 Computer Science · How a machine learns
Examples instead of rules
When the rule cannot be written, and what is done then.
You know how to do it, and cannot write it down
You recognize a friend’s handwriting in a quarter of a second. Try writing a condition that tells the letter a from the letter o in handwriting, in every shape people write them. After half an hour you will still have no function that works. So how does a computer learn to do it anyway?
Everything you have written until now was an explicit rule: if this then that, repeat this, return that. There are tasks at which you know how to perform and cannot state the rule. You recognise handwriting in a quarter of a second, and cannot write a condition distinguishing the letters. That is where this approach enters.
# ordinary: the rule is written, the answers follow
def is_spam(text):
return "free money" in text.lower()
# learned: the answers are given, the rule follows
examples = [
("free money now", True),
("meeting at four", False),
("claim your prize", True),
]
# a procedure reads these and produces a rule nobody wroteWhat is needed for this to work
Three conditions, and when one of them is missing the approach does not fit. Many examples — a rule derived from three examples is not a rule but a coincidence. Labelled examples — each example needs the right answer, and usually a person has to write it. And a resemblance between past and future — the rule is derived from what was, and if reality changes it stops fitting without warning.
| The approach | What is given | What comes out |
|---|---|---|
| Ordinary programming | A rule | Answers |
| Learning from examples | Examples and answers | A rule |
Example 1 — why handwriting is not a rule
- You recognise a letter at once.
- And cannot state the condition.
- Examples are plentiful.
Example 2 — why three examples do not suffice
- Every possible rule fits three.
- There is no way to choose between them.
- The rule that comes out will be a coincidence.