NLP
Intent Recognition
Slot Filling
Natural Language Processing
Machine Learning

How to proceed with NLP task for recognizing intent and slots

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Intent recognition and slot filling are the core understanding tasks behind assistants, chatbots, and voice interfaces. The first predicts what the user wants to do, and the second extracts the values needed to complete that action, so the project succeeds only when both the label set and the training data are designed carefully.

Define the Intent and Slot Schema First

Before choosing a model, define the ontology of your system:

  • intents such as book_flight, cancel_reservation, or check_weather
  • slots such as from_city, to_city, date, or airline

Keep the schema tight. If two intents differ only in downstream business logic, they may not need separate NLP labels. Likewise, slots should represent reusable concepts, not one-off phrases.

A single training example usually contains both the utterance and its labels:

json
1{
2  "text": "book a flight from Toronto to Vancouver on Friday",
3  "intent": "book_flight",
4  "slots": [
5    ["from_city", "Toronto"],
6    ["to_city", "Vancouver"],
7    ["date", "Friday"]
8  ]
9}

For token-level training, convert slot spans into BIO tags.

text
1book      O
2a         O
3flight    O
4from      O
5Toronto   B-from_city
6to        O
7Vancouver B-to_city
8on        O
9Friday    B-date

That representation is standard, easy to inspect, and works with many sequence models.

Build a Labeled Dataset Before Thinking About Models

A small but clean dataset is more valuable than a large inconsistent one. Collect multiple ways users express the same intent, including abbreviations, typos, and reordered phrases.

For intent recognition, balance the number of examples per intent as much as you can. For slot filling, make sure each slot appears in enough linguistic contexts to generalize.

Here is a simple Python structure for storing examples:

python
1examples = [
2    {
3        "text": "book a flight from Toronto to Vancouver on Friday",
4        "intent": "book_flight",
5        "tokens": ["book", "a", "flight", "from", "Toronto", "to", "Vancouver", "on", "Friday"],
6        "tags": ["O", "O", "O", "O", "B-from_city", "O", "B-to_city", "O", "B-date"],
7    },
8    {
9        "text": "cancel my reservation for tomorrow",
10        "intent": "cancel_reservation",
11        "tokens": ["cancel", "my", "reservation", "for", "tomorrow"],
12        "tags": ["O", "O", "O", "O", "B-date"],
13    },
14]

Even if you later train a transformer, building and reviewing data in a simple human-readable format helps catch labeling errors early.

Start with a Baseline, Then Move to a Joint Model

A practical workflow is:

  1. build a baseline intent classifier
  2. build a baseline slot tagger
  3. move to a joint transformer model if the product needs more accuracy

For intent classification, a bag-of-words or TF-IDF baseline is still useful because it is fast to train and easy to debug.

python
1from sklearn.feature_extraction.text import TfidfVectorizer
2from sklearn.linear_model import LogisticRegression
3
4texts = [x["text"] for x in examples]
5labels = [x["intent"] for x in examples]
6
7vectorizer = TfidfVectorizer(ngram_range=(1, 2))
8X = vectorizer.fit_transform(texts)
9
10model = LogisticRegression(max_iter=1000)
11model.fit(X, labels)
12
13print(model.predict(vectorizer.transform(["book me a flight to Calgary"])))

For slots, a sequence tagger is needed. Traditional CRF models can work well for small structured datasets, while transformer-based token classifiers usually perform better once you have enough labeled data.

A joint model, where one encoder feeds both the intent head and the slot head, is often the best long-term choice because intent and slots inform each other. For example, the meaning of "Friday" depends on whether the utterance is about booking, canceling, or checking status.

Evaluate Intent and Slots Separately

Do not collapse everything into one accuracy number. Intent recognition should be evaluated with classification metrics such as accuracy or macro F1. Slot filling should be evaluated with entity-level F1, not just per-token accuracy, because one wrong boundary can break a useful extraction.

Also test complete semantic correctness: an utterance is only fully correct when both the intent and all required slots are correct. That metric reflects user experience better than isolated model scores.

Common Pitfalls

  • Designing too many overlapping intents. The model cannot separate labels that humans do not define clearly.
  • Treating slot filling like plain keyword matching. Context and token boundaries matter.
  • Using per-token accuracy as the main slot metric. Entity-level F1 is much more informative.
  • Focusing on model architecture before fixing annotation quality. Bad labels will dominate the error profile.

Summary

  • Start by defining a clear intent set and slot schema.
  • Store training examples with both an intent label and BIO-style slot tags.
  • Build strong baselines before investing in more complex joint models.
  • Evaluate intent and slot performance separately, then measure end-to-end semantic success.
  • Dataset quality and schema design usually matter more than model complexity early on.

Course illustration
Course illustration

All Rights Reserved.