Rule-Based Systems Versus Learned Models
Machine learning is a method of creating intelligent applications by presenting a program with a large collection of data.
The Spam Folder Problem
Imagine you are responsible for an email program. You want incoming messages that look like junk to land in a spam folder instead of the inbox. The broad question behind this task is how to get a program to make decisions like this on its own, and how the approach taken by machine learning differs from other approaches.
Keep this spam filter in mind as you read. It is a concrete problem that makes the contrast between two ways of building intelligent behavior easy to see. Each message that arrives is an input, and the filter's job is to produce an output: spam folder or inbox. The interesting question is where the logic that connects input to output comes from.
Tracing a Handcoded Rule Chain
In the early days of intelligent applications, many systems relied on handcoded rules. These are explicit if and else decisions that process data or adjust to user input. A person with expertise in the problem writes each rule down, and the program simply applies them in order. Nothing about the program is learned from data; the rules are the program's entire decision logic.
A spam filter built this way might use a blacklist of words. If an incoming message contains a word on the list, the message is marked as spam and moved to the spam folder. The designer decides which words belong on the list, and that decision is the entire intelligence of the system. This is an example of using an expert-designed rule system to build an intelligent application.
Read the diagram as a trace. The message enters at the top, and the only check is whether any blacklisted word appears. The answer to that single yes or no question determines the output. If the check is answered yes, the decision comes out as spam folder. If it is answered no, the decision comes out as inbox. There is no step where the program weighs evidence or learns anything new; the outcome is fixed by the rule the designer wrote.
spam folder
inbox- The blacklist is the knowledge the designer wrote down by hand.
- The loop checks each rule in turn, which is the if and else chain in action.
- The lowercase conversion means the rule matches regardless of capitalization.
- The final return is the fallback decision when no rule fires.
What do you think happens?
Using the blacklist in the code above, where does the message 'Your free money is waiting' get routed?
Reveal answer
spam folder
The lowercased message contains the blacklisted phrase 'free money', so the first rule fires and the function returns 'spam folder' before reaching the fallback.
Routing two messages through the blacklist
A blacklist contains the words 'free money' and 'act now'. Determine the output for the messages 'Act now to claim a prize' and 'Lunch at noon?'.
- 1Message one
The message is lowercased, and the check looks for each blacklisted word. It contains 'act now', so the first matching rule fires.
- 2Decision for message one
Because a rule matched, the program stops checking and sends the message to the spam folder.
- 3Message two
The message is lowercased and checked against 'free money' and then 'act now'. Neither phrase appears.
- 4Decision for message two
No rule fires, so the fallback sends the message to the inbox.
'Act now to claim a prize' goes to the spam folder, and 'Lunch at noon?' goes to the inbox.
Where the Decision Logic Comes From
Machine learning takes a different route. Rather than having a person spell out the decision rules, it is a method of creating intelligent applications by presenting a program with a large collection of data. The program is not handed the rule; it works out what matters from the examples it sees.
The source describes this as a method that allows algorithms to determine the characteristics needed to identify a specific entity, such as a face, from a large collection of data. The key shift is in where the knowledge comes from. In a handcoded system, the knowledge lives in the rules a person wrote. In a machine learning system, the knowledge is extracted from the data.
Read the two columns side by side. Both aim to produce an intelligent application, and in both cases an input goes in and a decision comes out. They disagree about the middle of the process. In the left column a person writes the criteria, and the program applies them. In the right column the criteria are not written in advance; they are determined by the algorithm from the data it is given.
How an Algorithm Learns From Examples
The source uses the example of identifying a face within images. A person could try to write explicit rules describing a face, but the source frames the machine learning approach as one where the algorithm itself determines the characteristics needed to identify the entity from a large collection of data. The program's knowledge is therefore a product of what it was shown.
Notice what the diagram does not contain: a list of rules written by a person. The characteristics sit between the data and the prediction, and they were produced by the algorithm. The same pattern applies to the spam filter. Instead of asking a designer which words belong on a blacklist, a learning approach would derive what distinguishes spam from non-spam from a large collection of messages.
Why Hand-Written Rules Hit a Ceiling
Hand-written rules are not a bad idea by default. The source notes that crafting decision rules manually is feasible for some applications, particularly those where humans understand the process being modeled well. When the rules can be stated clearly by someone who knows the domain, a rule system can work well.
The source states that using handcoded rules to make decisions has two major disadvantages. The core issue is that a rule system depends entirely on what the designer thought to write down. When the problem is too intricate for a person to specify in full, the rules become the bottleneck, because the program can only decide what its rules already cover.
The examples the source gives, a spam filter and identifying a face in images, both involve deciding something about data that a person might find hard to capture in explicit rules. This is the pattern that makes learned models attractive. When a designer cannot state the criteria completely, the approach that determines characteristics from examples has a route that a rule list does not.
Mistakes When Comparing the Two Approaches
Learners often make predictable errors when they first contrast the two approaches. The list below names the most common ones and corrects each.
Common mistake Assuming a rule system is automatically unintelligent
What it looks likeDismissing the blacklist filter because it is 'just if statements'.
Why it failsThe source treats the blacklist as an example of using an expert-designed rule system to build an intelligent application.
Do this insteadJudge a rule system by how well the designer's knowledge matches the problem, not by whether it contains if and else.
Common mistake Thinking machine learning means no human choices are made
What it looks likeBelieving the algorithm invents everything from nothing.
Why it failsThe source says the algorithm works from a large collection of data that people choose to present to it.
Do this insteadRecognize that the data supplied to the program still shapes what it learns.
Common mistake Confusing where the knowledge lives
What it looks likeSaying the learned approach has no logic because nobody wrote rules.
Why it failsIn a machine learning system, the knowledge is extracted from the data rather than absent.
Do this insteadAsk where the decision logic comes from: a person's written rules, or characteristics the algorithm determined from examples.
Common mistake Treating every problem as a candidate for hand-written rules without asking whether humans understand the process well enough to model it
Practice: Locating the Decision Logic
For each system below, decide whether its decision logic comes from rules written by a person or from characteristics an algorithm determines from a large collection of data. (a) A spam filter whose blacklist of words was typed in by an expert. (b) An application that identifies faces by learning characteristics from many images. Explain your reasoning in terms of where the knowledge lives.
Hints
- Ask who decides which words or features matter: the designer or the program.
- The source says a machine learning algorithm determines the characteristics needed to identify an entity such as a face.
Suppose a blacklist filter keeps missing spam that uses a word not on the list. Explain, using the idea of a bottleneck, why adding more words by hand is the only fix the rule system itself offers, and describe what the learning approach changes about that problem.
Hints
- Think about what the rule system can decide: only what its rules already cover.
- Compare where the knowledge comes from in each approach.
Key Takeaways
- Machine learning builds intelligent applications by presenting a program with a large collection of data, so the program works out what matters from examples rather than being handed explicit rules.
- A handcoded rule system makes decisions through explicit if and else checks written by a person; a spam filter's blacklist of words is a standard example.
- Hand-written rules are feasible mainly where humans understand the process well enough to model it, and the source states they have two major disadvantages, with the rule set limited to what the designer thought to specify.
- The core contrast is where the decision logic comes from: in a handcoded system it lives in rules a person wrote, while in a machine learning system the algorithm extracts the characteristics it needs from data.