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 your training data is in english, a good starting point is using pretrained_embeddings_convert pipeline.

language: "en"
pipeline: "pretrained_embeddings_convert"

In case your training data is multi-lingual and is rich with domain specific vocabulary, use the supervised_embeddings pipeline:

language: "en"
pipeline: "supervised_embeddings"

A Longer Answer

The three most important pipelines are supervised_embeddings, pretrained_embeddings_convert and pretrained_embeddings_spacy. The pretrained_embeddings_spacy pipeline uses pre-trained word vectors from either GloVe or fastText, whereas pretrained_embeddings_convert uses a pretrained sentence encoding model ConveRT to extract vector representations of complete user utterance as a whole. On the other hand, the supervised_embeddings pipeline doesn’t use any pre-trained word vectors or sentence vectors, but instead fits these specifically for your dataset.

pretrained_embeddings_spacy

The advantage of 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 large enough training data.

pretrained_embeddings_convert

Warning
Since ConveRT model is trained only on an English corpus of conversations, this pipeline should only be used if your training data is in English language.

This pipeline uses ConveRT model to extract vector representation of a sentence and feeds them to EmbeddingIntentClassifier for intent classification. The advantage of using pretrained_embeddings_convert pipeline is that it doesn’t treat each word of the user message independently, but creates a contextual vector representation for the complete sentence.

Note
To use pretrained_embeddings_convert pipeline, you should install tensorflow-text==1.15.1 and tensorflow-hub==0.6.0. Otherwise, you can also pip install Rasa with pip install rasa[convert]. Please also note that tensorflow-text is only currently supported on Linux platforms.

supervised_embeddings

The advantage of the supervised_embeddings pipeline is that your word vectors will be customized 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.

You can read more about this topic here .

MITIE

You can also use MITIE as a source of word vectors in your pipeline, see MITIE. The MITIE backend performs well for small datasets, but training can take very long if you have more than a couple of hundred examples.

Rasa gives you the tools to compare the performance of both of these pipelines on your data directly, see Comparing NLU Pipelines.

Class imbalance

Classification algorithms often do not perform well if there is a large class imbalance, for example if you have a lot of training data for some intents and very little training data for others. To mitigate this problem, rasa’s supervised_embeddings pipeline uses a balanced batching strategy.

language: "en"
pipeline:
- name: "CountVectorsFeaturizer"
- name: "EmbeddingIntentClassifier"
  batch_strategy: sequence

Multiple Intents

If you want to split intents into multiple labels, e.g. for predicting multiple intents or for modeling hierarchical intent structure, you can only do this with the supervised embeddings pipeline.

Here’s an example configuration:

language: "en"
pipeline:
- name: "WhitespaceTokenizer"
  intent_split_symbol: "_"
- name: "CountVectorsFeaturizer"
- name: "EmbeddingIntentClassifier"

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, response selection, pre-processing, and others. If you want to add your own component, for example to run a spell-check or to do sentiment analysis, check out Custom NLU Components.

Each component processes the input and creates an output. For example, for the sentence "I am looking for Chinese food" the output is:

{
    "text": "I am looking for Chinese food",
    "entities": [
        {"start": 8, "end": 15, "value": "chinese", "entity": "cuisine", "extractor": "CRFEntityExtractor", "confidence": 0.864}
    ],
    "intent": {"confidence": 0.6485910906220309, "name": "restaurant_search"},
    "intent_ranking": [
        {"confidence": 0.6485910906220309, "name": "restaurant_search"},
        {"confidence": 0.1416153159565678, "name": "affirm"}
    ]
}

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. Lets assume, we added the following pipeline to our config: "pipeline": ["Component A", "Component B", "Last Component"]. The image shows the call order during the training of this pipeline:

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: the extractor field of an entity tells you which entity extractor found this particular entity, and the processors field contains the name of components that altered this specific entity.

{
  "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. For example, these two configurations are equivalent:

language: "en"
pipeline: "pretrained_embeddings_spacy"
language: "en"
pipeline:
- name: "SpacyNLP"
- name: "SpacyTokenizer"
- name: "SpacyFeaturizer"
- name: "RegexFeaturizer"
- name: "CRFEntityExtractor"
- name: "EntitySynonymMapper"
- name: "SklearnIntentClassifier"

Below is a list of all the pre-configured pipeline templates with customization information.