# Training Data Format

The training data for Rasa NLU is structured into different parts:

- common examples
- synonyms
- regex features and
- lookup tables

While common examples is the only part that is mandatory, including the others will help the NLU model learn the domain with fewer examples and also help it be more confident of its predictions.

## Data Formats

You can provide training data as Markdown or as JSON, as a single file or as a directory containing multiple files.
Note that Markdown is usually easier to work with.

### Markdown Format

Markdown is the easiest Rasa NLU format for humans to read and write. Examples are listed using the unordered list syntax, e.g. minus `-`, asterisk `*`, or plus `+`. Examples are grouped by intent, and entities are annotated as Markdown links, e.g. `[entity](entity name)`.

```markdown
## intent:check_balance
- what is my balance <!-- no entity -->
- how much do I have on my [savings](source_account) <!-- entity "source_account" has value "savings" -->
- how much do I have on my [savings account](source_account:savings) <!-- synonyms, method 1-->
- Could I pay in [yen](currency)?  <!-- entity matched by lookup table -->

## intent:greet
- hey
- hello

## synonym:savings   <!-- synonyms, method 2 -->
- pink pig

## regex:zipcode
- [0-9]{5}

## lookup:currencies   <!-- lookup table list -->
- Yen
- USD
- Euro

## lookup:additional_currencies  <!-- no list to specify lookup table file -->
path/to/currencies.txt
```

The training data for Rasa NLU is structured into different parts:

- common examples
- synonyms
- regex features
- lookup tables

### JSON Format

The JSON format consists of a top-level object called `rasa_nlu_data`, with the keys `common_examples`, `entity_synonyms` and `regex_features`.

```json
{
    "rasa_nlu_data": {
        "common_examples": [],
        "regex_features": [],
        "lookup_tables": [],
        "entity_synonyms": []
    }
}
```

The `common_examples` are used to train your model. You should put all of your training examples in the `common_examples` array. Regex features are a tool to help the classifier detect entities or intents and improve the performance.

## Improving Intent Classification and Entity Recognition

### Common Examples

Common examples have three components: `text`, `intent` and `entities`. The first two are strings while the last one is an array.

> - The _text_ is the user message \[required\]
> - The _intent_ is the intent that should be associated with the text \[optional\]
> - The _entities_ are specific parts of the text which need to be identified \[optional\]

Entities are specified with a `start` and an `end` value, which together make a python style range to apply to the string, e.g. in the example below, with `text="show me chinese restaurants"`, then `text[8:15] == 'chinese'`. Entities can span multiple words, and in fact the `value` field does not have to correspond exactly to the substring in your example.

```markdown
## intent:restaurant_search
- show me [chinese](cuisine) restaurants
```

### Regular Expression Features

Regular expressions can be used to support the intent classification and entity extraction. For example, if your entity has a deterministic structure (like a zipcode or an email address), you can use a regular expression to ease detection of that entity. For the zipcode example it might look like this:

```markdown
## regex:zipcode
- [0-9]{5}

## regex:greet
- hey[^\\s]*
```

### Lookup Tables

Lookup tables in the form of external files or lists of elements may also be specified in the training data. The externally supplied lookup tables must be in a newline-separated format. For example, `data/test/lookup_tables/plates.txt` may contain:

```markdown
tacos
beef
mapo tofu
burrito
lettuce wrap
```

And can be loaded as:

```markdown
## lookup:plates
data/test/lookup_tables/plates.txt
```

### Normalizing Data

### Entity Synonyms

If you define entities as having the same value they will be treated as synonyms. Here is an example of that:

```markdown
## intent:search
- in the center of [NYC](city:New York City)
- in the centre of [New York City](city)
```

To use the synonyms defined in your training data, you need to make sure the pipeline contains the `EntitySynonymMapper` component.

### Generating More Entity Examples

It is sometimes helpful to generate a bunch of entity examples, for example if you have a database of restaurant names. There are a couple of tools built by the community to help with that.
