Choosing a Pipeline

Choosing a Pipeline

Choosing an NLU pipeline allows you to customize your model and finetune it on your dataset.

The Short Answer

If you have less than 1000 total training examples, and there is a spaCy model for your language, use the pretrained_embeddings_spacy pipeline:

language: "en"

pipeline: "pretrained_embeddings_spacy"

If you have 1000 or more labelled utterances, use the supervised_embeddings pipeline:

language: "en"

pipeline: "supervised_embeddings"

A Longer Answer

The two most important pipelines are supervised_embeddings and pretrained_embeddings_spacy. The biggest difference between them is that the pretrained_embeddings_spacy pipeline uses pre-trained word vectors from either GloVe or fastText. The supervised_embeddings pipeline, on the other hand, doesn’t use any pre-trained word vectors, but instead fits these specifically for your dataset.

pretrained_embeddings_spacy

The advantage of the pretrained_embeddings_spacy pipeline is that if you have a training example like: “I want to buy apples”, and Rasa is asked to predict the intent for “get pears”, your model already knows that the words “apples” and “pears” are very similar. This is especially useful if you don’t have very much training data.

supervised_embeddings

The advantage of the supervised_embeddings pipeline is that your word vectors will be customised for your domain. For example, in general English, the word “balance” is closely related to “symmetry”, but very different to the word “cash”. In a banking domain, “balance” and “cash” are closely related and you’d like your model to capture that.

Comparing different pipelines for your data

Rasa gives you the tools to compare the performance of both of these pipelines on your data directly. Note: Intent classification is independent of entity extraction. So sometimes NLU will get the intent right but entities wrong, or the other way around.

Multiple Intents

If you want to split intents into multiple labels, you can only do this with the supervised embeddings pipeline. To do this, use these flags:

Here’s an example configuration:

language: "en"

pipeline:
- name: "CountVectorsFeaturizer"
- name: "EmbeddingIntentClassifier"
  intent_tokenization_flag: true
  intent_split_symbol: "+"

Understanding the Rasa NLU Pipeline

In Rasa NLU, incoming messages are processed by a sequence of components. These components are executed one after another in a so-called processing pipeline. There are components for entity extraction, for intent classification, pre-processing, and others.

Component Lifecycle

Every component can implement several methods from the Component base class; in a pipeline these different methods will be called in a specific order.

The “entity” object explained

After parsing, the entity is returned as a dictionary. There are two fields that show information about how the pipeline impacted the entities returned.

{
  "text": "show me chinese restaurants",
  "intent": "restaurant_search",
  "entities": [
    {
      "start": 8,
      "end": 15,
      "value": "chinese",
      "entity": "cuisine",
      "extractor": "CRFEntityExtractor",
      "confidence": 0.854,
      "processors": []
    }
  ]
}

Pre-configured Pipelines

A template is just a shortcut for a full list of components. Here are the default components that make up the supervised_embeddings pipeline:

language: "en"

pipeline:
- name: "WhitespaceTokenizer"
- name: "RegexFeaturizer"
- name: "CRFEntityExtractor"
- name: "EntitySynonymMapper"
- name: "CountVectorsFeaturizer"
- name: "EmbeddingIntentClassifier"

Custom pipelines

You can also run a fully custom pipeline by listing the names of the components you want to use:

pipeline:
- name: "SpacyNLP"
- name: "CRFEntityExtractor"
- name: "EntitySynonymMapper"