Skip to content

Commit 2d6f5a4

Browse files
committed
[Cogsvcs] LUIS - pattern syntax as reference
1 parent 5a5576e commit 2d6f5a4

File tree

3 files changed

+140
-120
lines changed

3 files changed

+140
-120
lines changed

articles/cognitive-services/LUIS/luis-concept-patterns.md

Lines changed: 5 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.custom: seodec18
99
ms.service: cognitive-services
1010
ms.subservice: language-understanding
1111
ms.topic: conceptual
12-
ms.date: 10/15/2019
12+
ms.date: 11/11/2019
1313
ms.author: diberry
1414
---
1515
# Patterns improve prediction accuracy
@@ -52,128 +52,16 @@ Given enough example utterances, LUIS would be able to increase prediction confi
5252
## Pattern matching
5353
A pattern is matched based on detecting the entities inside the pattern first, then validating the rest of the words and word order of the pattern. Entities are required in the pattern for a pattern to match. The pattern is applied at the token level, not the character level.
5454

55-
## Pattern syntax
56-
Pattern syntax is a template for an utterance. The template should contain words and entities you want to match as well as words and punctuation you want to ignore. It is **not** a regular expression.
57-
58-
Entities in patterns are surrounded by curly brackets, `{}`. Patterns can include entities, and entities with roles. [Pattern.any](luis-concept-entity-types.md#patternany-entity) is an entity only used in patterns.
59-
60-
Pattern syntax supports the following syntax:
61-
62-
|Function|Syntax|Nesting level|Example|
63-
|--|--|--|--|
64-
|entity| {} - curly brackets|2|Where is form {entity-name}?|
65-
|optional|[] - square brackets<BR><BR>There is a limit of 3 on nesting levels of any combination of optional and grouping |2|The question mark is optional [?]|
66-
|grouping|() - parentheses|2|is (a \| b)|
67-
|or| \| - vertical bar (pipe)<br><br>There is a limit of 2 on the vertical bars (Or) in one group |-|Where is form ({form-name-short} &#x7c; {form-name-long} &#x7c; {form-number})|
68-
|beginning and/or end of utterance|^ - caret|-|^begin the utterance<br>the utterance is done^<br>^strict literal match of entire utterance with {number} entity^|
69-
70-
## Nesting syntax in patterns
71-
72-
The **optional** syntax, with square brackets, can be nested two levels. For example: `[[this]is] a new form`. This example allows for the following utterances:
73-
74-
|Nested optional utterance example|Explanation|
75-
|--|--|
76-
|this is a new form|matches all words in pattern|
77-
|is a new form|matches outer optional word and non-optional words in pattern|
78-
|a new form|matches required words only|
79-
80-
The **grouping** syntax, with parentheses, can be nested two levels. For example: `(({Entity1.RoleName1} | {Entity1.RoleName2} ) | {Entity2} )`. This feature allows any of the three entities to be matched.
81-
82-
If Entity1 is a Location with roles such as origin (Seattle) and destination (Cairo) and Entity 2 is a known building name from a list entity (RedWest-C), the following utterances would map to this pattern:
83-
84-
|Nested grouping utterance example|Explanation|
85-
|--|--|
86-
|RedWest-C|matches outer grouping entity|
87-
|Seattle|matches one of the inner grouping entities|
88-
|Cairo|matches one of the inner grouping entities|
89-
90-
## Nesting limits for groups with optional syntax
91-
92-
A combination of **grouping** with **optional** syntax has a limit of 3 nesting levels.
93-
94-
|Allowed|Example|
95-
|--|--|
96-
|Yes|( [ ( test1 &#x7c; test2 ) ] &#x7c; test3 )|
97-
|No|( [ ( [ test1 ] &#x7c; test2 ) ] &#x7c; test3 )|
98-
99-
## Nesting limits for groups with or-ing syntax
100-
101-
A combination of **grouping** with **or-ing** syntax has a limit of 2 vertical bars.
102-
103-
|Allowed|Example|
104-
|--|--|
105-
|Yes|( test1 &#x7c; test2 &#x7c; ( test3 &#x7c; test4 ) )|
106-
|No|( test1 &#x7c; test2 &#x7c; test3 &#x7c; ( test4 &#x7c; test5 ) ) |
107-
108-
## Syntax to add an entity to a pattern template
109-
To add an entity into the pattern template, surround the entity name with curly braces, such as `Who does {Employee} manage?`.
110-
111-
|Pattern with entity|
112-
|--|
113-
|`Who does {Employee} manage?`|
114-
115-
## Syntax to add an entity and role to a pattern template
116-
An entity role is denoted as `{entity:role}` with the entity name followed by a colon, then the role name. To add an entity with a role into the pattern template, surround the entity name and role name with curly braces, such as `Book a ticket from {Location:Origin} to {Location:Destination}`.
117-
118-
|Pattern with entity roles|
119-
|--|
120-
|`Book a ticket from {Location:Origin} to {Location:Destination}`|
121-
122-
## Syntax to add a pattern.any to pattern template
123-
The Pattern.any entity allows you to add an entity of varying length to the pattern. As long as the pattern template is followed, the pattern.any can be any length.
124-
125-
To add a **Pattern.any** entity into the pattern template, surround the Pattern.any entity with the curly braces, such as `How much does {Booktitle} cost and what format is it available in?`.
126-
127-
|Pattern with Pattern.any entity|
128-
|--|
129-
|`How much does {Booktitle} cost and what format is it available in?`|
130-
131-
|Book titles in the pattern|
132-
|--|
133-
|How much does **steal this book** cost and what format is it available in?|
134-
|How much does **ask** cost and what format is it available in?|
135-
|How much does **The Curious Incident of the Dog in the Night-Time** cost and what format is it available in?|
136-
137-
The words of the book title are not confusing to LUIS because LUIS knows where the book title ends, based on the Pattern.any entity.
138-
139-
## Explicit lists
140-
141-
create an [Explicit List](https://westus.dev.cognitive.microsoft.com/docs/services/5890b47c39e2bb17b84a55ff/operations/5ade550bd5b81c209ce2e5a8) through the authoring API to allow the exception when:
142-
143-
* Your pattern contains a [Pattern.any](luis-concept-entity-types.md#patternany-entity)
144-
* And that pattern syntax allows for the possibility of an incorrect entity extraction based on the utterance.
145-
146-
For example, suppose you have a pattern containing both optional syntax, `[]`, and entity syntax, `{}`, combined in a way to extract data incorrectly.
147-
148-
Consider the pattern `[find] email about {subject} [from {person}]'.
149-
150-
In the following utterances, the **subject** and **person** entity are extracted correctly and incorrectly:
151-
152-
|Utterance|Entity|Correct extraction|
153-
|--|--|:--:|
154-
|email about dogs from Chris|subject=dogs<br>person=Chris||
155-
|email about the man from La Mancha|subject=the man<br>person=La Mancha|X|
156-
157-
In the preceding table, the subject should be `the man from La Mancha` (a book title) but because the subject includes the optional word `from`, the title is incorrectly predicted.
158-
159-
To fix this exception to the pattern, add `the man from la mancha` as an explicit list match for the {subject} entity using the [authoring API for explicit list](https://westus.dev.cognitive.microsoft.com/docs/services/5890b47c39e2bb17b84a55ff/operations/5ade550bd5b81c209ce2e5a8).
160-
161-
## Syntax to mark optional text in a template utterance
162-
Mark optional text in the utterance using the regular expression square bracket syntax, `[]`. The optional text can nest square brackets up to two brackets only.
163-
164-
|Pattern with optional text|Meaning|
165-
|--|--|
166-
|`[find] email about {subject} [from {person}]`|`find` and `from {person}` are optional|
167-
|`Can you help me[?]|The punctuation mark is optional|
168-
169-
Punctuation marks (`?`, `!`, `.`) should be ignored and you need to ignore them using the square bracket syntax in patterns.
170-
17155
## Pattern-only apps
17256
You can build an app with intents that have no example utterances, as long as there's a pattern for each intent. For a pattern-only app, the pattern shouldn't contain machine-learned entities because these do require example utterances.
17357

17458
## Best practices
17559
Learn [best practices](luis-concept-best-practices.md).
17660

61+
## Pattern syntax
62+
63+
Learn pattern syntax from the [pattern syntax reference](reference-pattern-syntax.md).
64+
17765
## Next steps
17866

17967
> [!div class="nextstepaction"]
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: Pattern syntax reference - LUIS
3+
titleSuffix: Azure Cognitive Services
4+
description: Create entities to extract key data from user utterances in Language Understanding (LUIS) apps. Extracted data is used by the client application.
5+
services: cognitive-services
6+
author: diberry
7+
manager: nitinme
8+
ms.service: cognitive-services
9+
ms.subservice: language-understanding
10+
ms.topic: reference
11+
ms.date: 11/11/2019
12+
ms.author: diberry
13+
---
14+
15+
## Pattern syntax
16+
17+
Pattern syntax is a template for an utterance. The template should contain words and entities you want to match as well as words and punctuation you want to ignore. It is **not** a regular expression.
18+
19+
Entities in patterns are surrounded by curly brackets, `{}`. Patterns can include entities, and entities with roles. [Pattern.any](luis-concept-entity-types.md#patternany-entity) is an entity only used in patterns.
20+
21+
Pattern syntax supports the following syntax:
22+
23+
|Function|Syntax|Nesting level|Example|
24+
|--|--|--|--|
25+
|entity| {} - curly brackets|2|Where is form {entity-name}?|
26+
|optional|[] - square brackets<BR><BR>There is a limit of 3 on nesting levels of any combination of optional and grouping |2|The question mark is optional [?]|
27+
|grouping|() - parentheses|2|is (a \| b)|
28+
|or| \| - vertical bar (pipe)<br><br>There is a limit of 2 on the vertical bars (Or) in one group |-|Where is form ({form-name-short} &#x7c; {form-name-long} &#x7c; {form-number})|
29+
|beginning and/or end of utterance|^ - caret|-|^begin the utterance<br>the utterance is done^<br>^strict literal match of entire utterance with {number} entity^|
30+
31+
## Nesting syntax in patterns
32+
33+
The **optional** syntax, with square brackets, can be nested two levels. For example: `[[this]is] a new form`. This example allows for the following utterances:
34+
35+
|Nested optional utterance example|Explanation|
36+
|--|--|
37+
|this is a new form|matches all words in pattern|
38+
|is a new form|matches outer optional word and non-optional words in pattern|
39+
|a new form|matches required words only|
40+
41+
The **grouping** syntax, with parentheses, can be nested two levels. For example: `(({Entity1.RoleName1} | {Entity1.RoleName2} ) | {Entity2} )`. This feature allows any of the three entities to be matched.
42+
43+
If Entity1 is a Location with roles such as origin (Seattle) and destination (Cairo) and Entity 2 is a known building name from a list entity (RedWest-C), the following utterances would map to this pattern:
44+
45+
|Nested grouping utterance example|Explanation|
46+
|--|--|
47+
|RedWest-C|matches outer grouping entity|
48+
|Seattle|matches one of the inner grouping entities|
49+
|Cairo|matches one of the inner grouping entities|
50+
51+
## Nesting limits for groups with optional syntax
52+
53+
A combination of **grouping** with **optional** syntax has a limit of 3 nesting levels.
54+
55+
|Allowed|Example|
56+
|--|--|
57+
|Yes|( [ ( test1 &#x7c; test2 ) ] &#x7c; test3 )|
58+
|No|( [ ( [ test1 ] &#x7c; test2 ) ] &#x7c; test3 )|
59+
60+
## Nesting limits for groups with or-ing syntax
61+
62+
A combination of **grouping** with **or-ing** syntax has a limit of 2 vertical bars.
63+
64+
|Allowed|Example|
65+
|--|--|
66+
|Yes|( test1 &#x7c; test2 &#x7c; ( test3 &#x7c; test4 ) )|
67+
|No|( test1 &#x7c; test2 &#x7c; test3 &#x7c; ( test4 &#x7c; test5 ) ) |
68+
69+
## Syntax to add an entity to a pattern template
70+
To add an entity into the pattern template, surround the entity name with curly braces, such as `Who does {Employee} manage?`.
71+
72+
|Pattern with entity|
73+
|--|
74+
|`Who does {Employee} manage?`|
75+
76+
## Syntax to add an entity and role to a pattern template
77+
An entity role is denoted as `{entity:role}` with the entity name followed by a colon, then the role name. To add an entity with a role into the pattern template, surround the entity name and role name with curly braces, such as `Book a ticket from {Location:Origin} to {Location:Destination}`.
78+
79+
|Pattern with entity roles|
80+
|--|
81+
|`Book a ticket from {Location:Origin} to {Location:Destination}`|
82+
83+
## Syntax to add a pattern.any to pattern template
84+
The Pattern.any entity allows you to add an entity of varying length to the pattern. As long as the pattern template is followed, the pattern.any can be any length.
85+
86+
To add a **Pattern.any** entity into the pattern template, surround the Pattern.any entity with the curly braces, such as `How much does {Booktitle} cost and what format is it available in?`.
87+
88+
|Pattern with Pattern.any entity|
89+
|--|
90+
|`How much does {Booktitle} cost and what format is it available in?`|
91+
92+
|Book titles in the pattern|
93+
|--|
94+
|How much does **steal this book** cost and what format is it available in?|
95+
|How much does **ask** cost and what format is it available in?|
96+
|How much does **The Curious Incident of the Dog in the Night-Time** cost and what format is it available in?|
97+
98+
The words of the book title are not confusing to LUIS because LUIS knows where the book title ends, based on the Pattern.any entity.
99+
100+
## Explicit lists
101+
102+
create an [Explicit List](https://westus.dev.cognitive.microsoft.com/docs/services/5890b47c39e2bb17b84a55ff/operations/5ade550bd5b81c209ce2e5a8) through the authoring API to allow the exception when:
103+
104+
* Your pattern contains a [Pattern.any](luis-concept-entity-types.md#patternany-entity)
105+
* And that pattern syntax allows for the possibility of an incorrect entity extraction based on the utterance.
106+
107+
For example, suppose you have a pattern containing both optional syntax, `[]`, and entity syntax, `{}`, combined in a way to extract data incorrectly.
108+
109+
Consider the pattern `[find] email about {subject} [from {person}]'.
110+
111+
In the following utterances, the **subject** and **person** entity are extracted correctly and incorrectly:
112+
113+
|Utterance|Entity|Correct extraction|
114+
|--|--|:--:|
115+
|email about dogs from Chris|subject=dogs<br>person=Chris||
116+
|email about the man from La Mancha|subject=the man<br>person=La Mancha|X|
117+
118+
In the preceding table, the subject should be `the man from La Mancha` (a book title) but because the subject includes the optional word `from`, the title is incorrectly predicted.
119+
120+
To fix this exception to the pattern, add `the man from la mancha` as an explicit list match for the {subject} entity using the [authoring API for explicit list](https://westus.dev.cognitive.microsoft.com/docs/services/5890b47c39e2bb17b84a55ff/operations/5ade550bd5b81c209ce2e5a8).
121+
122+
## Syntax to mark optional text in a template utterance
123+
Mark optional text in the utterance using the regular expression square bracket syntax, `[]`. The optional text can nest square brackets up to two brackets only.
124+
125+
|Pattern with optional text|Meaning|
126+
|--|--|
127+
|`[find] email about {subject} [from {person}]`|`find` and `from {person}` are optional|
128+
|`Can you help me[?]|The punctuation mark is optional|
129+
130+
Punctuation marks (`?`, `!`, `.`) should be ignored and you need to ignore them using the square bracket syntax in patterns.

articles/cognitive-services/LUIS/toc.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@
167167
items:
168168
- name: Add an intent
169169
href: luis-how-to-add-intents.md
170-
- name: Add entity to utterance
171-
href: luis-how-to-add-example-utterances.md
172-
- name: Add entity without utterance
170+
- name: Add an entity to extract data
173171
href: luis-how-to-add-entities.md
174172
displayName: roles, import
175173
- name: Use prebuilt models
@@ -307,6 +305,8 @@
307305
displayName: Calendar, Communication,Email,HomeAutomation,Note,Places, RestaurantReservation,ToDo,Utilities,Weather,Web
308306
- name: Custom entity reference
309307
items:
308+
- name: Machine-learned entity
309+
href: reference-entity-machine-learned-entity.md
310310
- name: Composite entity
311311
href: reference-entity-composite.md
312312
- name: List entity
@@ -317,6 +317,8 @@
317317
href: reference-entity-regular-expression.md
318318
- name: Simple entity
319319
href: reference-entity-simple.md
320+
- name: Pattern syntax
321+
href: reference-pattern-syntax.md
320322
- name: Sentiment
321323
href: luis-reference-prebuilt-sentiment.md
322324
- name: Developer resources

0 commit comments

Comments
 (0)