Choosing a Pipeline

Choosing a Pipeline

In Rasa Open Source, incoming messages are processed by a sequence of components. These components are executed one after another in a so-called processing pipeline defined in your config.yml. Choosing an NLU pipeline allows you to customize your model and finetune it on your dataset.

How to Choose a Pipeline

The Short Answer

If your training data is in English, a good starting point is the following pipeline:

language: "en"

pipeline:
  - name: ConveRTTokenizer
  - name: ConveRTFeaturizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: "char_wb"
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100

If your training data is not in English, start with the following pipeline:

language: "fr"  # your two-letter language code

pipeline:
  - name: WhitespaceTokenizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: "char_wb"
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100

A Longer Answer

We recommend using following pipeline, if your training data is in English:

language: "en"

The pipeline contains the [ConveRTFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#convertfeaturizer) that provides pre-trained word embeddings of the user utterance. Pre-trained word embeddings are helpful as they already encode some kind of linguistic knowledge. For example, if you have a sentence like “I want to buy apples” in your training data, 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 enough training data. The advantage of the [ConveRTFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#convertfeaturizer) is that it doesn’t treat each word of the user message independently, but creates a contextual vector representation for the complete sentence. However, `ConveRT` is only available in English.

If your training data is not in English, but you still want to use pre-trained word embeddings, we recommend using the following pipeline:

language: "fr" # your two-letter language code

pipeline:


It uses the [SpacyFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#spacyfeaturizer) instead of the [ConveRTFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#convertfeaturizer). [SpacyFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#spacyfeaturizer) provides pre-trained word embeddings from either GloVe or fastText in many different languages.

### Choosing the Right Components

There are components for entity extraction, for intent classification, response selection, pre-processing, and others. You can learn more about any specific component on the [Components](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#components) page. 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](https://legacy-docs-v1.rasa.com/1.10.9/api/custom-nlu-components/#custom-nlu-components).

A pipeline usually consists of three main parts:

- [Tokenization](https://legacy-docs-v1.rasa.com/1.10.9/nlu/choosing-a-pipeline/#tokenization)
- [Featurization](https://legacy-docs-v1.rasa.com/1.10.9/nlu/choosing-a-pipeline/#featurization)
- [Entity Recognition / Intent Classification / Response Selectors](https://legacy-docs-v1.rasa.com/1.10.9/nlu/choosing-a-pipeline/#entity-recognition-intent-classification-response-selectors)

#### Tokenization

For tokenization of English input, we recommend the [ConveRTTokenizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#converttokenizer). You can process other whitespace-tokenized (words are separated by spaces) languages with the [WhitespaceTokenizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#whitespacetokenizer). If your language is not whitespace-tokenized, you should use a different tokenizer. We support a number of different [tokenizers](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#tokenizers), or you can create your own [custom tokenizer](https://legacy-docs-v1.rasa.com/1.10.9/api/custom-nlu-components/#custom-nlu-components).

#### Featurization

You need to decide whether to use components that provide pre-trained word embeddings or not. We recommend in cases of small amounts of training data to start with pre-trained word embeddings. Once you have a larger amount of data and ensure that most relevant words will be in your data and therefore will have a word embedding, supervised embeddings, which learn word meanings directly from your training data, can make your model more specific to your domain. If you can’t find a pre-trained model for your language, you should use supervised embeddings.

##### Pre-trained Embeddings

The advantage of using pre-trained word embeddings in your 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 enough training data. We support a few components that provide pre-trained word embeddings:

1. [MitieFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#mitiefeaturizer)
2. [SpacyFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#spacyfeaturizer)
3. [ConveRTFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#convertfeaturizer)
4. [LanguageModelFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#languagemodelfeaturizer)

If your training data is in English, we recommend using the [ConveRTFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#convertfeaturizer). The advantage of the [ConveRTFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#convertfeaturizer) is that it doesn’t treat each word of the user message independently, but creates a contextual vector representation for the complete sentence.

An alternative to [ConveRTFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#convertfeaturizer) is the [LanguageModelFeaturizer](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#languagemodelfeaturizer).

##### Supervised Embeddings

If you don’t use any pre-trained word embeddings inside your pipeline, you are not bound to a specific language and can train your model to be more domain specific. You should only use featurizers from the category [sparse featurizers](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#text-featurizers).

#### Entity Recognition / Intent Classification / Response Selectors

Depending on your data you may want to only perform intent classification, entity recognition or response selection. Or you might want to combine multiple of those tasks. We support several components for each of the tasks. All of them are listed in [Components](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#components). We recommend using [DIETClassifier](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#diet-classifier) for intent classification and entity recognition and [ResponseSelector](https://legacy-docs-v1.rasa.com/1.10.9/nlu/components/#response-selector) for response selection.

### Multi-Intent Classification

You can use Rasa Open Source components to split intents into multiple labels. For example, you can predict multiple intents (`thank+goodbye`) or model hierarchical intent structure.

### Comparing Pipelines

Rasa gives you the tools to compare the performance of multiple pipelines on your data directly. See [Comparing NLU Pipelines](https://legacy-docs-v1.rasa.com/1.10.9/user-guide/testing-your-assistant/#comparing-nlu-pipelines) for more information.

### Handling Class Imbalance

Classification algorithms often do not perform well if there is a large class imbalance. To mitigate this problem, you can use a `balanced` batching strategy.

### Component Lifecycle

Each component processes an input and/or creates an output. The order of the components is determined by the order they are listed in the `config.yml`.