Free course · Lesson 5 of 5
A First Text Classifier
In this lesson you will
- Explain bag of words
- Read a classifier's prediction and confidence
A classifier needs numbers. The bag-of-words method counts how often each vocabulary word appears in each message. A model such as Naive Bayes learns which words go with which category, then chooses the most likely category for a new message.
- Train and test separately: keep some labelled messages aside to measure how well the model works on messages it has never seen.
- Look beyond accuracy: a confusion matrix shows which categories are mixed up, for example complaints sent to the enquiries queue.
- Use confidence: send messages with low predicted probability to a person instead of trusting the guess.
Practical Skill: Read every wrongly classified message and group the errors by cause (spelling, mixed language, very short message, wrong label). Each group suggests a fix.
Message: "When does the registration office open"Words the model knows: does, the, registration, office, open("when" never appeared in training, so it is ignored) Predicted probabilities: enquiry 0.91 <- chosen complaint 0.03 spam 0.03 request 0.02 Confident enough to route automatically. A message whose highestprobability is below 0.6 would go to a staff member instead.
Practice exercise
Using the worked example, predict which category the message 'Is the library open on Saturday' would get and explain why.
Key takeaways
- Classifiers learn which words go with which category
- Low-confidence predictions should go to a person
Free self-study lesson — no certificate. For the full instructor-led program, see registration options.