Intent Recognition

Let's see what intent recognition is and how we can use it for our chatbot.

We'll cover the following

Intent recognition (also called intent classification) is the task of classifying user utterances with predefined labels (intents). Intent classification is basically text classification. Intent classification is a well-known and common NLP task. GitHub and Kaggle host many intent classification datasets.

In real-world chatbot applications, we first determine the domain our chatbot has to function in, such as finance and banking, healthcare, marketing, and so on. Then we perform the following loop of actions:

  1. We determine a set of intents we want to support and prepare a labeled dataset of (utterance, label) pairs. We train our intent classifier on this dataset.

  2. Next, we deploy our chatbot to the users and gather real user data.

  3. Then we examine how our chatbot performed on real user data. At this stage, usually, we spot some new intents and some utterances our chatbot failed to recognize. We extend our set of intents with the new intents, add the unrecognized utterances to our training set, and retrain our intent classifier.

  4. We go to step 2 and perform steps 2-3 until chatbot NLU quality reaches a good level of accuracy (> 0.95).

Our dataset is a real-world dataset; it contains typos and grammatical mistakes. While designing our intent classifiers—especially while doing pattern-based classification—we need to be robust to such mistakes.

We'll do the intent recognition in two steps: pattern-based text classification and statistical text classification. We have already seen how to do statistical text classification with TensorFlow and Keras. We'll work with Tensorflow and Keras again, but before that, we'll see how to design a pattern-based text classifier.

Pattern-based text classification

Pattern-based classification means classifying text by matching a predefined list of patterns to the text. We compare a precompiled list of patterns against the utterances and check whether there's a match.

An immediate example is spam classification. If an email contains one of the patterns, such as "you won a lottery" and "I'm a Nigerian prince," then this email should be classified as spam. Pattern-based classifiers are combined with statistical classifiers to boost the overall system accuracy.

Contrary to statistical classifiers, pattern-based classifiers are easy to build. We don't need to put any effort into training a TensorFlow model at all. We will compile a list of patterns from our corpus and feed them to Matcher. Then, Matcher can look for pattern matches in utterances.

To build a pattern-based classifier, we first need to collect some patterns. For now, we'll classify utterances with the NONE label. Let's see some utterance examples first:

Get hands-on with 1200+ tech skills courses.