liveBook · Manning

Intent classification

As explained in Natural Language Processing in Action, Second Edition

Intent classification assigns text to a category representing the user's purpose or communicative intent.

A chatbot needs to decide what a person is trying to do before it can respond appropriately. Intent classification assigns a user message to a category representing that purpose. The label can select a reply, move the conversation to another node, or help a team see which requests need better coverage. section 12.2.1 section 12.3.1

Start with two labels: greeting and unknown. Split a message into words and check whether its first word appears in a list of greetings. This is a working classifier, but it recognizes only the wording its rule checks. Adding more conditions creates more categories; regular expressions offer another way to write rules. section 1.5.1

Listing 1.1 Keyword detection using str.split
>>> greetings = "Hi Hello Greetings".split()
>>> user_statement = "Hello Joshua"
>>> user_token_sequence = user_statement.split()
>>> user_token_sequence
['Hello', 'Joshua']
>>> if user_token_sequence[0] in greetings:
...     bot_reply = "Thermonuclear War is a strange game. "
...     bot_reply += "The only winning move is NOT TO PLAY."
>>> else:
...     bot_reply = "Would you like to play a nice game of chess?"
>>> bot_reply
'Thermonuclear War is a strange game. The only winning move is NOT TO PLAY.'

The Python example uses str.split() and a first-token lookup to choose between two replies. Change the opening word to see how the narrow rule affects the result. section 1.5.1

Different words, same intent

“Turn off the lights,” “lights out,” and “switch the lights off please” express the same request. Instead of preparing a rule for every phrasing, a machine-learning classifier can seek the best match among known intents. section 12.2.1

Classification also makes decisions before a response is generated. Given a numerical vector representation of a message, a classifier can make a discrete choice among routing options without asking an LLM to explain the choice. Semantic routing is one application. section 10.1.3

Choose categories with the people affected by mistakes in mind. A math tutor chatbot may need to recognize disclosures of abuse or self-harm, not just lesson requests. Such interactions call for safeguarding procedures; classification alone is not a substitute for them. Intent counts can also reveal common requests and gaps in a chatbot’s response templates. section 12.1.2 section 12.2.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Builds a two-category keyword rule and explains fuzzy classification and vector-based routing, without detailing classifier training.
Examples
Uses a Python greeting check, varied light-switching requests, and safeguarding needs in a math tutor chatbot.
What it assumes
Assumes basic Python for the executable rule; introduces intent categories before discussing vectors and routing.
What you can do after
Build it from scratch as a two-category Python keyword classifier and evaluate/understand when broader intent recognition matters.
How it connects
Connects intent labels to pattern matching, machine-learning classifiers, conversation graphs, semantic search, and semantic routing.

Also explained in

Compare how 4 books explain intent classification →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.