Pattern feature example with hyphenated names

This commit is contained in:
Denise Mak 2017-10-24 18:46:40 -07:00
Родитель 6dbcedd049
Коммит eb9d302d87
7 изменённых файлов: 282 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,84 @@
## Pattern Feature
The __[Pattern feature][LuisFeatures]__ can help your LUIS app recognize words and phrases that follow a pattern defined by a regular expression. The example describes how to create a LUIS app that uses a pattern feature to help recognize hyphenated names. You can import the sample LUIS app [here][SampleHyphenatedNamesModel].
### Defining a pattern for hyphenated names
Let's say your chatbot has a `MyNameIs` intent that detects when the user tells you their name, and a `Name` entity for detecting this name.
![screenshot of intent][Intents]
![screenshot of name entity][Entity]
To recognize names that have a hyphen, like "Ann-Marie", add some utterances to the MyNameIs intent that have names of this type.
![screenshot of utterances][Utterances]
To add a pattern feature, under **Features**, click **Pattern features** and then click the **Add pattern feature** button.
Enter `^\w+-\w+$` for the pattern value. The `^` indicates the beginning of the string. The `\w` indicates an alphanumeric character. The `+` indicates one or more occurences of the character preceding it.
![screenshot of adding the pattern][AddPattern]
### Test the app
In the **Train and Test** pane, click **Train Application**. Once your app is trained, you can see how the LUIS app can recognize hyphenated names in utterances.
![screenshot of interactive test][InteractiveTest]
### Publish the app
You can publish the LUIS app and view the results in a web browser.
#### Example results from published LUIS app
Paste a query to your published LUIS app into a web browser. The format of the URL should be similar to the one that follows.
```
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/YOUR-APP-ID?subscription-key=YOUR-SUBSCRIPTION-KEY&staging=true&verbose=true&timezoneOffset=0&q=my%20name%20is%20ann-marie
```
When the results are displayed in the browser you can see how the `Name` entity is identified. Note that in the `entity` field, LUIS inserts spaces around the hyphen, but the `startIndex` and `endIndex` fields identify the indexes of the entity in the original utterance.
```
{
"query": "my name is ann-marie",
"topScoringIntent": {
"intent": "MyNameIs",
"score": 0.9736568
},
"intents": [
{
"intent": "MyNameIs",
"score": 0.9736568
},
{
"intent": "None",
"score": 0.113408491
}
],
"entities": [
{
"entity": "ann - marie",
"type": "Name",
"startIndex": 11,
"endIndex": 19,
"score": 0.862268746
}
]
}
```
___
The LUIS app used in this example can be found __[here][SampleHyphenatedNamesModel]__.
Additional reading on __[LUIS Features][LuisFeatures]__ can be found here.
[Intents]: ./screenshots/intents.png
[Entity]: ./screenshots/name-entity.png
[Utterances]: ./screenshots/hyphen-utterances.png
[PatternFeatures]: ./screenshots/pattern-features.png
[AddPattern]: ./screenshots/add-pattern.png
[InteractiveTest]: ./screenshots/interactive-test.png
[SampleHyphenatedNamesModel]: ./hyphenated-names.json
[LuisFeatures]: https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-concept-feature

Просмотреть файл

@ -0,0 +1,198 @@
{
"luis_schema_version": "2.1.0",
"versionId": "0.1",
"name": "NamesWithHyphen",
"desc": "",
"culture": "en-us",
"intents": [
{
"name": "MyNameIs"
},
{
"name": "None"
}
],
"entities": [
{
"name": "Name"
}
],
"composites": [],
"closedLists": [],
"bing_entities": [],
"actions": [],
"model_features": [],
"regex_features": [
{
"name": "HyphenatedName",
"pattern": "^\\w+-\\w+$",
"activated": true
}
],
"utterances": [
{
"text": "i need help",
"intent": "None",
"entities": []
},
{
"text": "what does this app do?",
"intent": "None",
"entities": []
},
{
"text": "hi, my name is marc",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 15,
"endPos": 18
}
]
},
{
"text": "call me natalie",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 8,
"endPos": 14
}
]
},
{
"text": "i'm marie",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 4,
"endPos": 8
}
]
},
{
"text": "my name is denise",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 11,
"endPos": 16
}
]
},
{
"text": "i'm marie-antoinette",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 4,
"endPos": 19
}
]
},
{
"text": "i'm marie-anne",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 4,
"endPos": 13
}
]
},
{
"text": "the name is marie-anne",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 12,
"endPos": 21
}
]
},
{
"text": "call me jean-marc",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 8,
"endPos": 16
}
]
},
{
"text": "name is jean-luc",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 8,
"endPos": 15
}
]
},
{
"text": "my name is marc-andre",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 11,
"endPos": 20
}
]
},
{
"text": "the name is denise-ann. good morning.",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 12,
"endPos": 21
}
]
},
{
"text": "my name is john. nice to meet you",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 11,
"endPos": 14
}
]
},
{
"text": "call me jean-louis please",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 8,
"endPos": 17
}
]
},
{
"text": "bobbie-sue is my name",
"intent": "MyNameIs",
"entities": [
{
"entity": "Name",
"startPos": 0,
"endPos": 9
}
]
}
]
}

Двоичные данные
examples/pattern-feature/screenshots/add-pattern.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 14 KiB

Двоичные данные
examples/pattern-feature/screenshots/hyphen-utterances.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 29 KiB

Двоичные данные
examples/pattern-feature/screenshots/intents.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.9 KiB

Двоичные данные
examples/pattern-feature/screenshots/interactive-test.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 19 KiB

Двоичные данные
examples/pattern-feature/screenshots/name-entity.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 12 KiB