# Choosing a Pipeline

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

## [The Short Answer](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#the-short-answer)

If your training data is in english, a good starting point is using `pretrained_embeddings_convert` pipeline.

```yaml
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:

```yaml
language: "en"
pipeline: "supervised_embeddings"
```

## [A Longer Answer](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#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](https://github.com/PolyAI-LDN/polyai-models) 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.

Note: These recommendations are highly dependent on your dataset and hence approximate. We suggest experimenting with different pipelines to train the best model.

### [pretrained_embeddings_spacy](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#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](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#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](https://github.com/PolyAI-LDN/polyai-models) 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.

### [supervised_embeddings](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#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](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#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.

## [Class imbalance](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#class-imbalance)

Classification algorithms often do not perform well if there is a large class imbalance. To mitigate this problem, rasa’s `supervised_embeddings` pipeline uses a `balanced` batching strategy.  
In order to turn it off and use a classic batching strategy include `batch_strategy: sequence` in your config file.

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

## [Multiple Intents](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#multiple-intents)

If you want to split intents into multiple labels, you can only do this with the supervised embeddings pipeline using specific flags in `Whitespace Tokenizer`.  
Here’s an example configuration:

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

## [Understanding the Rasa NLU Pipeline](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#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 processing pipeline. 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.7.3/api/custom-nlu-components/#custom-nlu-components).

Each component processes the input and creates an output. The output can be used by any component that comes after this component in the pipeline.

## [Component Lifecycle](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#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. Before the first component is created using the `create` function, a context is created to pass information between the components.

## [The “entity” object explained](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-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.

```json
{
  "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](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#pre-configured-pipelines)

A template is just a shortcut for a full list of components. For example:

```yaml
language: "en"
pipeline: "pretrained_embeddings_spacy"
```

Another version of this pipeline includes using MITIE’s featurizer and its multi-class classifier.

## [Custom pipelines](https://legacy-docs-v1.rasa.com/1.7.3/nlu/choosing-a-pipeline/#custom-pipelines)

You don’t have to use a template, you can also run a fully custom pipeline by listing the names of the components you want to use:

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

### Example Configuration

```yaml
language: "en"
pipeline:
- name: "WhitespaceTokenizer"
- name: "CountVectorsFeaturizer"
- name: "EmbeddingIntentClassifier"
```
