NLU-based assistants
This section refers to building NLU-based assistants. If you are working with Conversational AI with Language Models (CALM), this content may not apply to you.Overview
Rasa uses YAML as a unified and extendable way to manage all NLU training data; intents and entities. Rasa Studio provides an additional layer on top of that, enabling the management of training data through a web-based interface. You can split the training data over any number of YAML files, and each file can contain any combination of NLU data. The training data parser determines the training data type using top level keys. The domain uses the same YAML format as the training data and can also be split across multiple files or combined in one file. The domain includes the definitions for responses. See the documentation for the domain for information on how to format your domain file.High-Level Structure
Each file can contain one or more keys with corresponding training data. One file can contain multiple keys, but each key can only appear once in a single file. The available keys are:versionnlu
version key in all YAML training data files.
If you don’t specify a version key in your training data file, Rasa
will assume you are using the latest training data format specification supported
by the version of Rasa you have installed.
Training data files with a Rasa version greater than the version you have
installed on your machine will be skipped.
Currently, the latest training data format specification for Rasa 3.x is 3.1.
Example
Here’s a short example which keeps all training data in a single file:nlu.yml
The | symbolAs shown in the above examples, the
user and examples keys are followed by |
(pipe) symbol. In YAML | identifies multi-line strings with preserved indentation.
This helps to keep special symbols like ", ' and others still available in the
training examples.NLU Training Data
NLU training data consists of example user utterances categorized by intent. Training examples can also include entities. Entities are structured pieces of information that can be extracted from a user’s message. You can also add extra information such as regular expressions and lookup tables to your training data to help the model identify intents and entities correctly. NLU training data is defined under thenlu key. Items that can be added under this key are:
- Training examples grouped by user intent e.g. optionally with annotated entities
nlu.yml
nlu.yml
nlu.yml
nlu.yml
Training Examples
Training examples are grouped by intent and listed under theexamples key. Usually, you’ll list one example per line as follows:
nlu.yml
nlu.yml
metadata key can contain arbitrary key-value data that is tied to an example and
accessible by the components in the NLU pipeline.
In the example above, the sentiment metadata could be used by a custom component in
the pipeline for sentiment analysis.
You can also specify this metadata at the intent level:
nlu.yml
metadata key is passed to every intent example.
If you want to specify retrieval intents, then your NLU examples will look as follows:
nlu.yml
ask_name and ask_weather are the suffixes. The suffix is separated from
the retrieval intent name by a / delimiter.
Special meaning of /As shown in the above examples, the
/ symbol is reserved as a delimiter to separate
retrieval intents from their associated response keys. Make sure not to use it in the
name of your intents.Entities
Entities are structured pieces of information that can be extracted from a user’s message. Entities are annotated in training examples with the entity’s name. In addition to the entity name, you can annotate an entity with synonyms, roles, or groups. In training examples, entity annotation would look like this:nlu.yml
role, group, and value are optional in this notation.
The value field refers to synonyms. To understand what the labels role and group are
for, see the section on entity roles and groups.
Synonyms
Synonyms normalize your training data by mapping an extracted entity to a value other than the literal text extracted. You can define synonyms using the format:nlu.yml
value of the entity:
nlu.yml
Regular Expressions
You can use regular expressions to improve intent classification and entity extraction using theRegexFeaturizer and RegexEntityExtractor components.
The format for defining a regular expression is as follows:
nlu.yml
account_number is the name of the regular expression. When used as features for the RegexFeaturizer the name of the regular expression does not matter. When using the RegexEntityExtractor, the name of the regular expression should match the name of the entity you want to extract.
Read more about when and how to use regular expressions with each component on the NLU Training Data page.
Lookup Tables
Lookup tables are lists of words used to generate case-insensitive regular expression patterns. The format is as follows:nlu.yml