CourseNatural Language Processing: The Complete Course · Module 4: Text as Vectors and Classification · part 28 of 73
Part 28 · Module 4: Text as Vectors and Classification

Lesson 3: Naive Bayes, the first trained intent classifier

54 min read·14 Oct 2026
Module 4 · Lesson 3 · About 45 minutes · Needs: basic Python; Module 2 Lesson 3 helps (word tokens) but is not required

The situation

It is Monday 28 September 2026, project week 4. The keyword router from Module 1 scores 0.438 on HARD_TEST, the 80 hand-written messages. Every new keyword Ines suggests fixes one message and breaks another.

Rosa asks: Ines has labelled 1,800 messages (simulated), so can the computer work out the keywords itself? It can. This lesson builds naive Bayes, first by hand and then with scikit-learn, and scores it on the same 80 messages.

TWO WAYS TO ROUTE A MESSAGE keyword rules written by hand 0.438 on HARD_TEST learned evidence counted from labels 1,262 labelled messages Each new keyword fixed one message and broke another.
The keyword router (grey, written by hand) stalls at 0.438 on HARD_TEST; a trained model (blue) learns its word evidence from 1,262 labelled messages instead.

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.