Skip to content

Commit b21e32e

Browse files
committed
added rasa material
1 parent 470f94a commit b21e32e

File tree

2 files changed

+222
-31
lines changed

2 files changed

+222
-31
lines changed

Module 4 - Machine Learning/02. Working with Text Data/6. Chatbots Development using RASA/intro_to_rasa.ipynb

+222-31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
" - RASA Command Line Interface (CLI)\n",
2020
" - Important Terminologies\n",
2121
"3. Building the First RASA Project\n",
22+
" - Initial Setup\n",
23+
" - Stories Visualization\n",
2224
" - Creating NLU Training Data\n",
2325
" - Customizing Dialogue Management\n",
2426
"4. RASA Developer Certificate Exam\n",
@@ -110,13 +112,14 @@
110112
"\n",
111113
"### **Important Terminology**\n",
112114
"Let's learn the foundational components used for structuring conversations within Rasa, such as an intent, entity, slot, form, response, action, rule, or story.\n",
113-
"1. **Story:** Training data format for the dialogue model, consisting of a conversation between a user and a bot. The user's messages are represented as annotated intents and entities, and the bot’s responses are represented as a sequence of actions.\n",
114-
"2. **Intent:** In a given user message, the thing that a user is trying to convey or accomplish (e,g., greeting, specifying a location).\n",
115-
"3. **Entity:** Keywords that can be extracted from a user message. For example: a telephone number, a person's name, a location, the name of a product.\n",
116-
"4. **Slot:** A key-value store that Rasa uses to track information over the course of a conversation.\n",
117-
"5. **Forms:** One of the most common conversation patterns is to collect a few pieces of information from a user in order to do something (book a restaurant, call an API, search a database, etc.). This is also called **slot filling**.\n",
118-
"6. **Response / Template / Utterance:** A message that an assistant sends to a user. This can include text, buttons, images, and other content.\n",
119-
"7. **Rules:** Special training data to specify rule-like behavior, where a specific condition always predicts a specific next action. Examples include answering FAQs, filling Forms, or handling Fallbacks."
115+
"1. **Story: (defined inside `data/stories.yml`)** Training data format for the dialogue model, consisting of a conversation between a user and a bot. The user's messages are represented as annotated intents and entities, and the bot’s responses are represented as a sequence of actions.\n",
116+
"2. **Intent: (defined inside `data/nlu.yml`)** In a given user message, the thing that a user is trying to convey or accomplish (e,g., greeting, specifying a location).\n",
117+
"3. **Entity: (defined inside `data/nlu.yml`)** Keywords that can be extracted from a user message. For example: a telephone number, a person's name, a location, the name of a product.\n",
118+
"4. **Response / Template / Utterance: (defined inside `domain.yml`)** A message that an assistant sends to a user. This can include text, buttons, images, and other content.\n",
119+
"5. **Slot: (defined inside `domain.yml`)** A key-value store that Rasa uses to track information over the course of a conversation. There are various slot types like: text, categorical, float, bool and list.\n",
120+
"6. **Slot Mapping: (defined inside `domain.yml`)** Slot mappings allow you to define how each slot will be filled in. Slot mappings are applied after each user message. There are various slot mapping types like: from_entity, from_intent, etc...\n",
121+
"7. **Forms: (defined inside `domain.yml`)** One of the most common conversation patterns is to collect a few pieces of information from a user in order to do something (book a restaurant, call an API, search a database, etc.). This is also called **slot filling**.\n",
122+
"8. **Rules: (defined inside `data/rules.yml`)** Special training data to specify rule-like behavior, where a specific condition always predicts a specific next action. Examples include answering FAQs, filling Forms, or handling Fallbacks."
120123
]
121124
},
122125
{
@@ -126,6 +129,7 @@
126129
"source": [
127130
"## **Building the First RASA Project**\n",
128131
"\n",
132+
"### **Initial Setup**\n",
129133
"1. **Create a new RASA Project:**\n",
130134
"```bash\n",
131135
"rasa init # Initialize a new project\n",
@@ -144,6 +148,16 @@
144148
"```"
145149
]
146150
},
151+
{
152+
"cell_type": "markdown",
153+
"id": "92e11e92-eda3-4952-8ee7-6371145449a1",
154+
"metadata": {},
155+
"source": [
156+
"### **Stories Visualization**\n",
157+
"\n",
158+
"<img src=\"images/rasa_visualize.png\">"
159+
]
160+
},
147161
{
148162
"cell_type": "markdown",
149163
"id": "0aa4529f-1fc3-46dc-b2dc-9c1ecdc71a4e",
@@ -153,26 +167,99 @@
153167
"\n",
154168
"Define intents and entities in `data/nlu.yml`:\n",
155169
"```yaml\n",
156-
"version: \"2.0\"\n",
170+
"version: \"3.1\"\n",
171+
"\n",
157172
"nlu:\n",
158173
"- intent: greet\n",
159174
" examples: |\n",
160175
" - hello\n",
161176
" - hi\n",
162177
" - hey\n",
178+
" - good morning\n",
179+
" - good evening\n",
180+
" - hey there\n",
181+
"\n",
182+
"- intent: goodbye\n",
183+
" examples: |\n",
184+
" - bye\n",
185+
" - goodbye\n",
186+
" - see you later\n",
187+
" - see you soon\n",
188+
" - catch you later\n",
189+
"\n",
190+
"- intent: thankyou\n",
191+
" examples: |\n",
192+
" - thanks\n",
193+
" - thank you\n",
194+
" - thank you very much\n",
195+
" - thanks a lot\n",
196+
" - much appreciated\n",
163197
"\n",
164198
"- intent: book_flight\n",
165199
" examples: |\n",
166-
" - I want to book a flight to [Paris](location)\n",
167-
" - Book a flight to [New York](location)\n",
200+
" - I want to book a flight\n",
201+
" - I need to book a flight\n",
202+
" - Can you help me book a flight?\n",
203+
" - I'd like to book a flight\n",
204+
" - Help me book a flight\n",
205+
"\n",
206+
"- intent: inform\n",
207+
" examples: |\n",
208+
" - I'm departing from [San Francisco](departure_city)\n",
209+
" - I want to fly to [New York](destination_city)\n",
210+
" - My departure city is [Los Angeles](departure_city)\n",
211+
" - I'm going to [Miami](destination_city)\n",
212+
" - I'll be leaving from [Chicago](departure_city)\n",
213+
" - I need a flight to [Dallas](destination_city)\n",
214+
" - My destination is [Boston](destination_city)\n",
215+
" - I'll be traveling to [Seattle](destination_city)\n",
216+
" - The departure date is [June 15th](departure_date)\n",
217+
" - I'm leaving on [July 20th](departure_date)\n",
218+
" - [June 10th](departure_date) for departure\n",
219+
" - The departure date is [2024-06-15](departure_date)\n",
220+
" - I'm leaving on [2025-07-01](departure_date)\n",
221+
" - [2024-01-10](departure_date) for departure\n",
222+
" - The return date is [June 30th](return_date)\n",
223+
" - I'll be back on [August 5th](return_date)\n",
224+
" - Return on [July 25th](return_date)\n",
225+
" - The return date is [2024-06-15](return_date)\n",
226+
" - I'll be back on [2025-07-01](return_date)\n",
227+
" - Return on [2024-01-10](return_date)\n",
228+
"\n",
229+
"- intent: stop\n",
230+
" examples: |\n",
231+
" - stop\n",
232+
" - cancel\n",
233+
" - never mind\n",
234+
" - forget it\n",
235+
" - no more\n",
236+
"\n",
237+
"- intent: out_of_scope\n",
238+
" examples: |\n",
239+
" - Tell me a joke\n",
240+
" - What's the weather like?\n",
241+
" - How are you?\n",
242+
" - Who won the game last night?\n",
243+
" - Do you know any good restaurants?\n",
168244
"```\n",
169245
"\n",
170-
"For every **new intent** created, add it in `domain.yml`. \n",
246+
"For every **new intent and entity** created in nlu, add it in `domain.yml`. \n",
171247
"\n",
172248
"```yaml\n",
173249
"intents:\n",
174250
" - greet\n",
251+
" - goodbye\n",
252+
" - thankyou\n",
175253
" - book_flight\n",
254+
" - inform\n",
255+
" - stop\n",
256+
" - out_of_scope\n",
257+
"\n",
258+
"entities:\n",
259+
" - departure_city\n",
260+
" - destination_city\n",
261+
" - departure_date\n",
262+
" - return_date\n",
176263
"```"
177264
]
178265
},
@@ -186,44 +273,148 @@
186273
"Define stories in `data/stories.yml`:\n",
187274
"```yaml\n",
188275
"version: \"2.0\"\n",
276+
"\n",
189277
"stories:\n",
190-
"- story: greet and respond\n",
191-
" steps:\n",
192-
" - intent: greet\n",
193-
" - action: utter_greet\n",
194-
"\n",
195-
"- story: book a flight\n",
196-
" steps:\n",
197-
" - intent: book_flight\n",
198-
" - action: utter_ask_location\n",
199-
" - intent: inform\n",
200-
" - action: utter_confirm_booking\n",
278+
" # Happy path\n",
279+
" - story: happy path\n",
280+
" steps:\n",
281+
" - intent: greet\n",
282+
" - action: utter_greet\n",
283+
" - intent: book_flight\n",
284+
" - action: utter_ask_departure_city\n",
285+
" - intent: inform\n",
286+
" entities:\n",
287+
" - departure_city\n",
288+
" - slot_was_set:\n",
289+
" - departure_city: \"San Francisco\"\n",
290+
" - action: utter_ask_destination_city\n",
291+
" - intent: inform\n",
292+
" entities:\n",
293+
" - destination_city\n",
294+
" - slot_was_set:\n",
295+
" - destination_city: \"New York\"\n",
296+
" - action: utter_ask_departure_date\n",
297+
" - intent: inform\n",
298+
" entities:\n",
299+
" - departure_date\n",
300+
" - slot_was_set:\n",
301+
" - departure_date: \"2024-06-15\"\n",
302+
" - action: utter_ask_return_date\n",
303+
" - intent: inform\n",
304+
" entities:\n",
305+
" - return_date\n",
306+
" - slot_was_set:\n",
307+
" - return_date: \"2024-06-20\"\n",
308+
" - action: utter_submit\n",
309+
"\n",
310+
" # User decides not to book a flight\n",
311+
" - story: user decides not to book a flight\n",
312+
" steps:\n",
313+
" - intent: greet\n",
314+
" - action: utter_greet\n",
315+
" - intent: book_flight\n",
316+
" - action: utter_ask_departure_city\n",
317+
" - intent: inform\n",
318+
" entities:\n",
319+
" - departure_city\n",
320+
" - slot_was_set:\n",
321+
" - departure_city: \"San Francisco\"\n",
322+
" - action: utter_ask_destination_city\n",
323+
" - intent: inform\n",
324+
" entities:\n",
325+
" - destination_city\n",
326+
" - slot_was_set:\n",
327+
" - destination_city: \"New York\"\n",
328+
" - action: utter_ask_departure_date\n",
329+
" - intent: stop\n",
330+
" - action: utter_goodbye\n",
331+
"\n",
332+
" # User goes out of scope\n",
333+
" - story: user goes out of scope\n",
334+
" steps:\n",
335+
" - intent: greet\n",
336+
" - action: utter_greet\n",
337+
" - intent: out_of_scope\n",
338+
" - action: utter_out_of_scope\n",
339+
"\n",
340+
" # User thanks the bot\n",
341+
" - story: user thanks the bot\n",
342+
" steps:\n",
343+
" - intent: greet\n",
344+
" - action: utter_greet\n",
345+
" - intent: thankyou\n",
346+
" - action: utter_thankyou\n",
347+
"\n",
348+
" # User says goodbye\n",
349+
" - story: user says goodbye\n",
350+
" steps:\n",
351+
" - intent: greet\n",
352+
" - action: utter_greet\n",
353+
" - intent: goodbye\n",
354+
" - action: utter_goodbye\n",
355+
"\n",
201356
"```\n",
202357
"\n",
203358
"Define actions, slots and responses in `domain.yml`:\n",
204359
"```yaml\n",
205360
"version: \"2.0\"\n",
206361
"intents:\n",
207362
" - greet\n",
363+
" - goodbye\n",
364+
" - thankyou\n",
208365
" - book_flight\n",
209366
" - inform\n",
367+
" - stop\n",
368+
" - out_of_scope\n",
210369
"\n",
211370
"entities:\n",
212-
" - location\n",
371+
" - departure_city\n",
372+
" - destination_city\n",
373+
" - departure_date\n",
374+
" - return_date\n",
213375
"\n",
214376
"slots:\n",
215-
" location:\n",
377+
" departure_city:\n",
378+
" type: text\n",
379+
" mappings:\n",
380+
" - type: from_entity\n",
381+
" entity: departure_city\n",
382+
" destination_city:\n",
383+
" type: text\n",
384+
" mappings:\n",
385+
" - type: from_entity\n",
386+
" entity: destination_city\n",
387+
" departure_date:\n",
388+
" type: text\n",
389+
" mappings:\n",
390+
" - type: from_entity\n",
391+
" entity: departure_date\n",
392+
" return_date:\n",
216393
" type: text\n",
394+
" mappings:\n",
395+
" - type: from_entity\n",
396+
" entity: return_date\n",
397+
"\n",
217398
"\n",
218399
"responses:\n",
219400
" utter_greet:\n",
220-
" - text: \"Hello! How can I assist you today?\"\n",
221-
"\n",
222-
" utter_ask_location:\n",
223-
" - text: \"Where would you like to fly to?\"\n",
224-
"\n",
225-
" utter_confirm_booking:\n",
226-
" - text: \"Your flight to {location} is booked!\"\n",
401+
" - text: \"Hi, I am a helpful assistant who can help you book a flight at your convinience.\"\n",
402+
" utter_ask_departure_city:\n",
403+
" - text: \"From which city are you departing?\"\n",
404+
" utter_ask_destination_city:\n",
405+
" - text: \"What is your destination city?\"\n",
406+
" utter_ask_departure_date:\n",
407+
" - text: \"What is your departure date?\"\n",
408+
" utter_ask_return_date:\n",
409+
" - text: \"What is your return date?\"\n",
410+
" utter_submit:\n",
411+
" - text: \"Your flight from {departure_city} to {destination_city} has been booked. Departure on {departure_date} and return on {return_date}.\"\n",
412+
" utter_goodbye:\n",
413+
" - text: \"Bye. Happy to help!\"\n",
414+
" utter_out_of_scope:\n",
415+
" - text: \"Hi, I am a helpful assistant who can help you book a flight at your convinience.\"\n",
416+
" utter_thankyou:\n",
417+
" - text: \"Happy to help! Is there anything else?\"\n",
227418
"```"
228419
]
229420
},

0 commit comments

Comments
 (0)