Skip to content

Commit ee6a399

Browse files
authored
Merge branch 'master' into change_defaults
2 parents 1ce2476 + 5506209 commit ee6a399

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2910
-1386
lines changed

changelog/3765.feature.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Add support for entities with roles and grouping of entities in Rasa NLU.
2+
3+
You can now define a role and/or group label in addition to the entity type for entities.
4+
Use the role label if an entity can play different roles in your assistant.
5+
For example, a city can be a destination or a departure city.
6+
The group label can be used to group multiple entities together.
7+
For example, you could group different pizza orders, so that you know what toppings goes with which pizza and
8+
what size which pizza has.
9+
For more details see :ref:`entities-roles-groups`.
10+
11+
To fill slots from entities with a specific role/group, you need to either use forms or use a custom action.
12+
We updated the tracker method ``get_latest_entity_values`` to take an optional role/group label.
13+
If you want to use a form, you can add the specific role/group label of interest to the slot mapping function
14+
``from_entity`` (see :ref:`forms``).
15+
16+
.. note::
17+
18+
Composite entities are currently just supported by the :ref:``diet-classifier`` and :ref:``CRFEntityExtractor``.

changelog/5230.bugfix.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fixed issue where posting to certain callback channel URLs would return a 500 error on successful posts due to invalid response format
1+
Fixed issue where posting to certain callback channel URLs would return a 500 error on successful posts due to invalid response format.

changelog/5465.feature.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Update training data format for NLU to support entities with a role or group label.
2+
3+
You can now specify synonyms, roles, and groups of entities using the following data format:
4+
Markdown:
5+
6+
.. code-block:: none
7+
8+
[LA]{"entity": "location", "role": "city", "group": "CA", "value": "Los Angeles"}
9+
10+
JSON:
11+
12+
.. code-block:: none
13+
14+
"entities": [
15+
{
16+
"start": 10,
17+
"end": 12,
18+
"value": "Los Angeles",
19+
"entity": "location",
20+
"role": "city",
21+
"group": "CA",
22+
}
23+
]
24+
25+
The markdown format ``[LA](location:Los Angeles)`` is deprecated. To update your training data file just
26+
execute the following command on the terminal of your choice:
27+
``sed -i .deprecated -E 's/\[(.*)\]\((.*):(.*)\)/\[\1\]\{"entity": "\2", "value": "\3"\}/g' nlu.md``
28+
29+
For more information about the new data format see :ref:`training-data-format`.
File renamed without changes.

changelog/5672.improvement.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Raise a warning in ``CRFEntityExtractor`` and ``DIETClassifier`` if entities are not correctly annotated in the
2+
training data, e.g. their start and end values do not match any start and end values of tokens.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## intent:affirm
2+
- yes
3+
- yep
4+
- yeah
5+
- indeed
6+
- that's right
7+
- ok
8+
- great
9+
- right, thank you
10+
- correct
11+
- great choice
12+
- sounds really good
13+
14+
## intent:goodbye
15+
- bye
16+
- goodbye
17+
- good bye
18+
- stop
19+
- end
20+
- farewell
21+
- Bye bye
22+
- have a good one
23+
24+
## intent:greet
25+
- hey
26+
- howdy
27+
- hey there
28+
- hello
29+
- hi
30+
- good morning
31+
- good evening
32+
- dear sir
33+
34+
## intent:chitchat
35+
- What's your name?
36+
- What can I call you?
37+
- How's the weather?
38+
- Is it too hot outside?
39+
40+
## intent:book_flight
41+
- i'm looking for a flight
42+
- I want to book a flight
43+
- i'm looking for a flight to [Berlin]{"entity": "location", "role": "to"}
44+
- show me flights from [Amsterdam]{"entity": "location", "role": "from"}
45+
- show me flights to [London]{"entity": "location", "role": "to"}
46+
- i am looking for a flight from [SF]{"entity": "location", "value": "San Fransisco", "role": "from"} to [New York]{"entity": "location", "role": "to"}
47+
- search for flights
48+
- from [Madrid]{"entity": "location", "role": "from"} to [Munich]{"entity": "location", "role": "to"}
49+
- any flight to [Liverpool]{"entity": "location", "role": "to"}
50+
51+
## intent:order_pizza
52+
- i want a [large]{"entity": "size", "group": "1"} pizza with [tomato]{"entity": "topping", "group": "1"} and a [small]{"entity": "size", "group": "2"} pizza with [bacon]{"entity": "topping", "group": "2"}
53+
- one [large]{"entity": "size", "group": "1"} with [pepperoni]{"entity": "topping", "group": "1"} and a [medium]{"entity": "size", "group": "2"} with [mushrooms]{"entity": "topping", "group": "2"}
54+
- I would like a [medium]{"entity": "size", "group": "1"} standard pizza and a [medium]{"entity": "size", "group": "2"} pizza with [extra cheese]{"entity": "topping", "group": "2"}
55+
- [large]{"entity": "size", "group": "1"} with [onions]{"entity": "topping", "group": "1"} and [small]{"entity": "size", "group": "2"} with [olives]{"entity": "topping", "group": "2"}
56+
- a pizza with [onions]{"entity": "topping", "group": "1"} in [medium]{"entity": "size", "group": "1"} and one with [mushrooms]{"entity": "topping", "group": "2"} in [small]{"entity": "size", "group": "2"} please

docs/core/forms.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ Here's an example for the restaurant bot:
142142

143143
The predefined functions work as follows:
144144

145-
- ``self.from_entity(entity=entity_name, intent=intent_name)``
145+
- ``self.from_entity(entity=entity_name, intent=intent_name, role=role_name, group=group_name)``
146146
will look for an entity called ``entity_name`` to fill a slot
147147
``slot_name`` regardless of user intent if ``intent_name`` is ``None``
148-
else only if the users intent is ``intent_name``.
148+
else only if the users intent is ``intent_name``. If ``role_name`` and/or ``group_name``
149+
are provided, the role/group label of the entity also needs to match the given values.
149150
- ``self.from_intent(intent=intent_name, value=value)``
150151
will fill slot ``slot_name`` with ``value`` if user intent is ``intent_name``.
151152
To make a boolean slot, take a look at the definition of ``outdoor_seating``

docs/nlu/entity-extraction.rst

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Component Requires Model Notes
3131
The "entity" Object
3232
^^^^^^^^^^^^^^^^^^^
3333

34-
After parsing, an entity is returned as a dictionary. There are two fields that show information
34+
After parsing, an entity is returned as a dictionary. There are two fields that show information
3535
about how the pipeline impacted the entities returned: the ``extractor`` field
3636
of an entity tells you which entity extractor found this particular entity, and
3737
the ``processors`` field contains the name of components that altered this
@@ -62,7 +62,7 @@ exactly. Instead it will return the trained synonym.
6262

6363
The ``confidence`` will be set by the ``CRFEntityExtractor`` component. The
6464
``DucklingHTTPExtractor`` will always return ``1``. The ``SpacyEntityExtractor`` extractor
65-
and ``DIETClassifier`` do not provide this information and returns ``null``.
65+
and ``DIETClassifier`` do not provide this information and return ``null``.
6666

6767

6868
Some extractors, like ``duckling``, may include additional information. For example:
@@ -98,11 +98,93 @@ Custom Entities
9898
Almost every chatbot and voice app will have some custom entities.
9999
A restaurant assistant should understand ``chinese`` as a cuisine,
100100
but to a language-learning assistant it would mean something very different.
101-
The ``CRFEntityExtractor`` component can learn custom entities in any language, given
101+
The ``CRFEntityExtractor`` and the ``DIETClassifier`` component can learn custom entities in any language, given
102102
some training data.
103103
See :ref:`training-data-format` for details on how to include entities in your training data.
104104

105105

106+
.. _entities-roles-groups:
107+
108+
Entities Roles and Groups
109+
^^^^^^^^^^^^^^^^^^^^^^^^^
110+
111+
.. warning::
112+
This feature is experimental.
113+
We introduce experimental features to get feedback from our community, so we encourage you to try it out!
114+
However, the functionality might be changed or removed in the future.
115+
If you have feedback (positive or negative) please share it with us on the `forum <https://forum.rasa.com>`_.
116+
117+
Assigning custom entity labels to words, allow you to define certain concepts in the data.
118+
For example, we can define what a `city` is:
119+
120+
.. code-block:: none
121+
122+
I want to fly from [Berlin](city) to [San Francisco](city).
123+
124+
However, sometimes you want to specify entities even further.
125+
Let's assume we want to build an assistant that should book a flight for us.
126+
The assistant needs to know which of the two cities in the example above is the departure city and which is the
127+
destination city.
128+
``Berlin`` and ``San Francisco`` are still cities, but they play a different role in our example.
129+
To distinguish between the different roles, you can assign a role label in addition to the entity label.
130+
131+
.. code-block:: none
132+
133+
- I want to fly from [Berlin]{"entity": "city", "role": "departure"} to [San Francisco]{"entity": "city", "role": "destination"}.
134+
135+
You can also group different entities by specifying a group label next to the entity label.
136+
The group label can, for example, be used to define different orders.
137+
In the following example we use the group label to reference what toppings goes with which pizza and
138+
what size which pizza has.
139+
140+
.. code-block:: none
141+
142+
Give me a [small]{"entity": "size", "group": "1"} pizza with [mushrooms]{"entity": "topping", "group": "1"} and
143+
a [large]{"entity": "size", "group": "2"} [pepperoni]{"entity": "topping", "group": "2"}
144+
145+
See :ref:`training-data-format` for details on how to define entities with roles and groups in your training data.
146+
147+
The entity object returned by the extractor will include the detected role/group label.
148+
149+
.. code-block:: json
150+
151+
{
152+
"text": "Book a flight from Berlin to SF",
153+
"intent": "book_flight",
154+
"entities": [
155+
{
156+
"start": 19,
157+
"end": 25,
158+
"value": "Berlin",
159+
"entity": "city",
160+
"role": "departure",
161+
"extractor": "DIETClassifier",
162+
},
163+
{
164+
"start": 29,
165+
"end": 31,
166+
"value": "San Francisco",
167+
"entity": "city",
168+
"role": "destination",
169+
"extractor": "DIETClassifier",
170+
}
171+
]
172+
}
173+
174+
.. note::
175+
176+
Composite entities are currently only supported by the :ref:``diet-classifier`` and :ref:``CRFEntityExtractor``.
177+
178+
In order to properly train your model with entities that have roles/groups, make sure to include enough training data
179+
examples for every combination of entity and role/group label.
180+
Also make sure to have some variations in your training data, so that the model is able to generalize.
181+
For example, you should not only have example like ``fly FROM x TO y``, but also include examples like
182+
``fly TO y FROM x``.
183+
184+
To fill slots from entities with a specific role/group, you need to either define a custom slot mappings using
185+
:ref:`forms` or use :ref:`custom-actions` to extract the corresponding entity directly from the tracker.
186+
187+
106188
Extracting Places, Dates, People, Organisations
107189
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108190

0 commit comments

Comments
 (0)