Skip to content

Commit b59bd73

Browse files
authored
Luis (#14)
* Luis in progress * Luis Runtime * Improve runtime example * Working booking sample * Mgmt part 1 * Mgmt final part * Update main README * Typo
1 parent 9883dee commit b59bd73

File tree

11 files changed

+659
-0
lines changed

11 files changed

+659
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This project framework provides examples for the following services:
1414

1515
### Language
1616

17+
* Using the **LUIS SDK** [azure-cognitiveservices-language-luis](http://pypi.python.org/pypi/azure-cognitiveservices-language-luis) for the [LUIS API](https://azure.microsoft.com/services/cognitive-services/language-understanding-intelligent-service/)
1718
* Using the **Bing Spell Check SDK** [azure-cognitiveservices-language-spellcheck](http://pypi.python.org/pypi/azure-cognitiveservices-language-spellcheck) for the [Bing Spell Check API](https://azure.microsoft.com/services/cognitive-services/spell-check/)
1819
* Using the **Text Analytics SDK** [azure-cognitiveservices-language-textanalytics](http://pypi.python.org/pypi/azure-cognitiveservices-language-textanalytics) for the [Tet Analytics API](https://azure.microsoft.com/services/cognitive-services/text-analytics/)
1920

@@ -78,6 +79,7 @@ We provide several meta-packages to help you install several packages at a time.
7879
pip install -r requirements.txt
7980
```
8081
82+
4. Set up the environment variable `LUIS_SUBSCRIPTION_KEY` with your key if you want to execute LUIS tests.
8183
4. Set up the environment variable `SPELLCHECK_SUBSCRIPTION_KEY` with your key if you want to execute SpellCheck tests.
8284
4. Set up the environment variable `TEXTANALYTICS_SUBSCRIPTION_KEY` with your key if you want to execute TextAnalytics tests. You might override too `TEXTANALYTICS_LOCATION` (westcentralus by default).
8385
3. Set up the environment variable `AUTOSUGGEST_SUBSCRIPTION_KEY` with your key if you want to execute Autosuggest tests.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
azure-cognitiveservices-language-luis
12
azure-cognitiveservices-language-spellcheck
23
azure-cognitiveservices-language-textanalytics
34
azure-cognitiveservices-search-autosuggest

samples/language/luis/LuisApp.json

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
{
2+
"luis_schema_version": "2.1.0",
3+
"versionId": "0.1",
4+
"name": "LuisBot",
5+
"desc": "",
6+
"culture": "en-us",
7+
"intents": [
8+
{
9+
"name": "dateintent"
10+
},
11+
{
12+
"name": "Help"
13+
},
14+
{
15+
"name": "None"
16+
},
17+
{
18+
"name": "SearchHotels"
19+
},
20+
{
21+
"name": "ShowHotelsReviews"
22+
}
23+
],
24+
"entities": [
25+
{
26+
"name": "AirportCode"
27+
},
28+
{
29+
"name": "Hotel"
30+
}
31+
],
32+
"composites": [],
33+
"closedLists": [],
34+
"bing_entities": [
35+
"datetimeV2"
36+
],
37+
"model_features": [
38+
{
39+
"name": "Near",
40+
"mode": true,
41+
"words": "near,around,close,nearby",
42+
"activated": true
43+
},
44+
{
45+
"name": "Show",
46+
"mode": true,
47+
"words": "show,find,look,search",
48+
"activated": true
49+
}
50+
],
51+
"regex_features": [
52+
{
53+
"name": "AirportCodeRegex",
54+
"pattern": "[a-z]{3}",
55+
"activated": true
56+
}
57+
],
58+
"utterances": [
59+
{
60+
"text": "i need help",
61+
"intent": "Help",
62+
"entities": []
63+
},
64+
{
65+
"text": "help me",
66+
"intent": "Help",
67+
"entities": []
68+
},
69+
{
70+
"text": "tomorrow",
71+
"intent": "dateintent",
72+
"entities": []
73+
},
74+
{
75+
"text": "search for hotels in seattle",
76+
"intent": "SearchHotels",
77+
"entities": []
78+
},
79+
{
80+
"text": "what can i do?",
81+
"intent": "Help",
82+
"entities": []
83+
},
84+
{
85+
"text": "next monday",
86+
"intent": "dateintent",
87+
"entities": []
88+
},
89+
{
90+
"text": "next year",
91+
"intent": "dateintent",
92+
"entities": []
93+
},
94+
{
95+
"text": "look for hotels in miami",
96+
"intent": "SearchHotels",
97+
"entities": []
98+
},
99+
{
100+
"text": "show me hotels in california",
101+
"intent": "SearchHotels",
102+
"entities": []
103+
},
104+
{
105+
"text": "show me the reviews of the amazing bot resort",
106+
"intent": "ShowHotelsReviews",
107+
"entities": [
108+
{
109+
"entity": "Hotel",
110+
"startPos": 23,
111+
"endPos": 44
112+
}
113+
]
114+
},
115+
{
116+
"text": "can i see the reviews of extended bot hotel?",
117+
"intent": "ShowHotelsReviews",
118+
"entities": [
119+
{
120+
"entity": "Hotel",
121+
"startPos": 25,
122+
"endPos": 42
123+
}
124+
]
125+
},
126+
{
127+
"text": "find reviews of hotelxya",
128+
"intent": "ShowHotelsReviews",
129+
"entities": [
130+
{
131+
"entity": "Hotel",
132+
"startPos": 16,
133+
"endPos": 23
134+
}
135+
]
136+
},
137+
{
138+
"text": "show me reviews of the amazing hotel",
139+
"intent": "ShowHotelsReviews",
140+
"entities": [
141+
{
142+
"entity": "Hotel",
143+
"startPos": 19,
144+
"endPos": 35
145+
}
146+
]
147+
},
148+
{
149+
"text": "what are the available options?",
150+
"intent": "Help",
151+
"entities": []
152+
},
153+
{
154+
"text": "best hotels in seattle",
155+
"intent": "SearchHotels",
156+
"entities": []
157+
},
158+
{
159+
"text": "hotels in los angeles",
160+
"intent": "SearchHotels",
161+
"entities": []
162+
},
163+
{
164+
"text": "can you show me hotels from los angeles?",
165+
"intent": "SearchHotels",
166+
"entities": []
167+
},
168+
{
169+
"text": "can you show me the reviews of the amazing resort & hotel",
170+
"intent": "ShowHotelsReviews",
171+
"entities": [
172+
{
173+
"entity": "Hotel",
174+
"startPos": 31,
175+
"endPos": 56
176+
}
177+
]
178+
},
179+
{
180+
"text": "what are the reviews of the hotel bot framework?",
181+
"intent": "ShowHotelsReviews",
182+
"entities": [
183+
{
184+
"entity": "Hotel",
185+
"startPos": 24,
186+
"endPos": 46
187+
}
188+
]
189+
},
190+
{
191+
"text": "find hotels near eze",
192+
"intent": "SearchHotels",
193+
"entities": [
194+
{
195+
"entity": "AirportCode",
196+
"startPos": 17,
197+
"endPos": 19
198+
}
199+
]
200+
},
201+
{
202+
"text": "where can i stay near nnn?",
203+
"intent": "SearchHotels",
204+
"entities": [
205+
{
206+
"entity": "AirportCode",
207+
"startPos": 22,
208+
"endPos": 24
209+
}
210+
]
211+
},
212+
{
213+
"text": "show hotels near att airport",
214+
"intent": "SearchHotels",
215+
"entities": [
216+
{
217+
"entity": "AirportCode",
218+
"startPos": 17,
219+
"endPos": 19
220+
}
221+
]
222+
},
223+
{
224+
"text": "find hotels near agl",
225+
"intent": "SearchHotels",
226+
"entities": [
227+
{
228+
"entity": "AirportCode",
229+
"startPos": 17,
230+
"endPos": 19
231+
}
232+
]
233+
},
234+
{
235+
"text": "find hotels around eze airport",
236+
"intent": "SearchHotels",
237+
"entities": [
238+
{
239+
"entity": "AirportCode",
240+
"startPos": 19,
241+
"endPos": 21
242+
}
243+
]
244+
},
245+
{
246+
"text": "01/7",
247+
"intent": "dateintent",
248+
"entities": []
249+
}
250+
]
251+
}

samples/language/luis/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
services: cognitive-services, luis, language-understanding
3+
platforms: python
4+
author: cahann, lmazuel
5+
---
6+
7+
# Cognitive Services: LUIS Runtime Sample
8+
9+
A example demonstrating how:
10+
- to consume the LUIS Authoring SDK to build an app or manage it
11+
- to consume the LUIS Runtime SDK to predict user utterances.
12+
13+
## Prerequisites
14+
15+
The minimum prerequisites to run this sample are:
16+
* A [LUIS.ai account](https://www.luis.ai/) where to upload the sample's LUIS model.
17+
18+
The first step is to get your Programmatic Key. Go to the home page, [www.luis.ai](https://www.luis.ai/), and log in. After creating your LUIS account, a starter key, also known as a programmatic key, is created automatically for LUIS account. To find the programmatic key, click on the account name in the upper-right navigation bar to open [Account Settings](https://www.luis.ai/user/settings), which displays the Programmatic Key.
19+
20+
![Get the programmatic key](images/programmatic-key.png)
21+
22+
Set the `LUIS_SUBSCRIPTION_KEY` environment variable to this programmtic key to continue.
23+
24+
## Cognitive Services: LUIS Authoring Sample
25+
26+
We provide two samples:
27+
28+
- The booking sample who is a complete example on how to create an app, create intents, utterances, training and publishing the app
29+
- The management example shows management operations: import or export an app/version, listing the different versions of an app, cloning a version, etc.
30+
31+
## Cognitive Services: LUIS Runtime Sample
32+
33+
#### LUIS Application
34+
35+
The first step to using LUIS is to create or import an application. Go to the home page, [www.luis.ai](https://www.luis.ai/), and log in. After creating your LUIS account you'll be able to Import an Existing Application where can you can select a local copy of the LuisApp.json file an import it.
36+
37+
![Import an Existing Application](images/prereqs-import.png)
38+
39+
If you want to test this sample, you have to import the pre-build [LuisApp.json](LuisApp.json) file to your LUIS account.
40+
41+
Once you imported the application you'll need to "train" the model ([Training](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/train-test)) before you can "Publish" the model in an HTTP endpoint. For more information, take a look at [Publishing a Model](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/publishapp).
42+
43+
Finally, edit the [luis_runtime_samples.py](luis_runtime_samples.py) file and update the attribute placeholders with the values corresponding to your Application and Azure Region where the application was deployed.
44+
45+
#### Where to find the Application ID and Subscription Key
46+
47+
You'll need these two values to configure the LuisDialog through the LuisModel attribute:
48+
49+
1. Application ID
50+
51+
You can find the App ID in the LUIS application's settings.
52+
53+
![App Settings](images/prereqs-appid.png)
54+
55+
2. Subscription Key and Azure Region
56+
57+
Click on the Publish App link from the top of the LUIS application dashboard. Once your app is published, copy the Region and Key String from *Starter_Key* from the Endpoints table on the Publish App page.
58+
59+
![Programmatic API Key](images/prereqs-apikey.png)
60+
61+
62+
### Code Highlights
63+
64+
One of the key problems in human-computer interactions is the ability of the computer to understand what a person wants, and to find the pieces of information that are relevant to their intent. In the LUIS application, you will bundle together the intents and entities that are important to your task. Read more about [Planning an Application](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/plan-your-app) in the [LUIS Docs](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/).
65+
66+
Once your model is set, you can invoke the LUIS Runtime API to analize user input and obtain its intent and possible entities.
67+
68+
From Python, use the [azure-cognitiveservices-language-luis](http://pypi.python.org/pypi/azure-cognitiveservices-language-luis) package.
69+
70+
````python
71+
from azure.cognitiveservices.language.luis.runtime import LUISRuntimeClient
72+
from msrest.authentication import CognitiveServicesCredentials
73+
74+
// Create client with SuscriptionKey and Azure region
75+
client = LUISRuntimeClient(
76+
'https://westus.api.cognitive.microsoft.com', # Change "westus" to your region if necessary
77+
CognitiveServicesCredentials("[LUIS_SUBSCRIPTION_KEY]"), # Put your LUIS Subscription key
78+
)
79+
80+
// Predict
81+
luis_result = client.prediction.resolve(
82+
"[LUIS_APPLICATION_ID]", # Put your LUIS Application ID
83+
"Text to Predict or User input"
84+
)
85+
````
86+
87+
The LuisResult object contains the possible detected intents and entities that could be extracted from the input.
88+
89+
### Outcome
90+
91+
You will see the following when running the application:
92+
93+
![Sample Outcome](images/outcome.png)
94+
95+
### More Information
96+
97+
To get more information about how to get started in Bot Builder for .NET and Conversations please review the following resources:
98+
* [Language Understanding Intelligent Service](https://azure.microsoft.com/en-us/services/cognitive-services/language-understanding-intelligent-service/)
99+
* [LUIS.ai](https://www.luis.ai)
100+
* [LUIS Docs](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/home)
101+
* [LUIS Runtime API v2 - Specification](https://github.com/Azure/azure-rest-api-specs/tree/current/specification/cognitiveservices/data-plane/LUIS/Runtime)
12.5 KB
Loading
98.6 KB
Loading
134 KB
Loading
20.9 KB
Loading
20.1 KB
Loading

0 commit comments

Comments
 (0)