|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "eb93ffaf-983a-4a12-a84c-b429dd078c4b", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# **Developing Chatbots using RASA**\n", |
| 9 | + "\n", |
| 10 | + "## **What's Covered?**\n", |
| 11 | + "1. Introduction to Chatbots\n", |
| 12 | + " - What are Chatbots?\n", |
| 13 | + " - Types of Chatbots\n", |
| 14 | + " - NLU and NLG in a Chatbot\n", |
| 15 | + "2. Introduction to RASA\n", |
| 16 | + " - Key Components\n", |
| 17 | + " - Why RASA?\n", |
| 18 | + " - Installing and Setting up RASA\n", |
| 19 | + " - RASA Command Line Interface (CLI)\n", |
| 20 | + " - Important Terminologies\n", |
| 21 | + "3. Building the First RASA Project\n", |
| 22 | + " - Creating NLU Training Data\n", |
| 23 | + " - Customizing Dialogue Management\n", |
| 24 | + "4. RASA Developer Certificate Exam\n", |
| 25 | + " - Exam Syllabus\n", |
| 26 | + " - Exam Link" |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "markdown", |
| 31 | + "id": "0095741f-7ce1-4bd6-bdc3-8ce55775adc1", |
| 32 | + "metadata": {}, |
| 33 | + "source": [ |
| 34 | + "## **Introduction to Chatbots**\n", |
| 35 | + "\n", |
| 36 | + "### **Q: What are Chatbots?**\n", |
| 37 | + "Chatbots are software applications designed to simulate human conversation. They can communicate with users through text or voice, providing automated responses based on user inputs. They are majorly used for:\n", |
| 38 | + "- Customer support\n", |
| 39 | + "- Virtual assistants\n", |
| 40 | + "\n", |
| 41 | + "### **Types of Chatbots:**\n", |
| 42 | + "- **Rule-based Chatbots:** Follow predefined rules and scripts to respond to user inputs.\n", |
| 43 | + "- **AI-based Chatbots:** Use machine learning and NLP to understand and respond to user inputs dynamically.\n", |
| 44 | + "\n", |
| 45 | + "### **NLU and NLG in a Chatbot**\n", |
| 46 | + "- **NLU:** Natural Language Understanding (NLU) deals with parsing and understanding human language into a structured format. \n", |
| 47 | + "- **NLG:** Natural Language Generation (NLG) is the process of generating natural language messages to send to a user. Rasa uses a simple template-based approach for NLG. Data-driven approaches (such as neural NLG) can be implemented by creating a custom NLG component." |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "markdown", |
| 52 | + "id": "d88d5711-e502-469a-a775-a829ce82f19f", |
| 53 | + "metadata": {}, |
| 54 | + "source": [ |
| 55 | + "## **Introduction to RASA**\n", |
| 56 | + "\n", |
| 57 | + "With over 25 million downloads, Rasa Open Source is the most popular open source framework for building chat and voice-based AI assistants.\n", |
| 58 | + "\n", |
| 59 | + "\n", |
| 60 | + "### **Key Components:**\n", |
| 61 | + "- **RASA NLU:** Understands user inputs by extracting intents and entities. `Dual Intent and Entity Transformer (DIET)` is the default NLU architecture used by Rasa, which performs both intent classification and entity extraction.\n", |
| 62 | + "- **RASA Core:** Manages the conversation flow and decides how to respond to user inputs. The dialogue engine that decides what to do next in a conversation based on the context. The `Transformer Embedding Dialogue (TED) Policy` is a multi-task architecture for next action prediction and entity recognition. \n", |
| 63 | + "\n", |
| 64 | + "### **Why RASA?**\n", |
| 65 | + "- **Faster:** Runs locally - no HTTP requests or server round trips required\n", |
| 66 | + "- **Customizable:** Tune models and get higher accuracy with your data set\n", |
| 67 | + "- **Open source:** No risk of vendor lock-in - Rasa is under the Apache 2.0 license and you can use it in commercial projects\n", |
| 68 | + "\n", |
| 69 | + "### **Installing and Setting up RASA**\n", |
| 70 | + "1. **Supported Versions of Python:**\n", |
| 71 | + "Currently, rasa supports the following Python versions: 3.7, 3.8, 3.9 and 3.10. Note that Python 3.10 is only supported for versions 3.4.x and upwards. Additionally, rasa installation on Apple Silicon with Python 3.10 is not functional in 3.4.x but will be supported starting from 3.5.x.\n", |
| 72 | + "You can check the python version installed on your system using this command in terminal/command prompt:\n", |
| 73 | + "```bash\n", |
| 74 | + "python --version\n", |
| 75 | + "```\n", |
| 76 | + "2. **Virtual Environment Setup:**\n", |
| 77 | + "In order to create a virtual environment, run the following command in terminal/command prompt:\n", |
| 78 | + "```bash\n", |
| 79 | + "python -m venv your_env_name\n", |
| 80 | + "```\n", |
| 81 | + "\n", |
| 82 | + "3. **Activate the Virtual Environment:**\n", |
| 83 | + "Run the following command to activate the virtual environment:\n", |
| 84 | + "```bash\n", |
| 85 | + "your_env_name\\Scripts\\activate\n", |
| 86 | + "```\n", |
| 87 | + "\n", |
| 88 | + "4. **Installing RASA Open Source:**\n", |
| 89 | + "Run the following command in terminal/command prompt:\n", |
| 90 | + "```bash\n", |
| 91 | + "pip install rasa\n", |
| 92 | + "```\n", |
| 93 | + "\n", |
| 94 | + "5. **Creating a New RASA Project:**\n", |
| 95 | + "```bash\n", |
| 96 | + "rasa init\n", |
| 97 | + "```\n", |
| 98 | + "\n", |
| 99 | + "### **RASA Command Line Interface (CLI)**\n", |
| 100 | + "- `rasa init` - Creates a new project with example training data, actions, and config files.\n", |
| 101 | + "- `rasa shell` - Loads your trained model and lets you talk to your assistant on the command line.\n", |
| 102 | + "- `rasa run` - Starts a server with your trained model.\n", |
| 103 | + "- `rasa interactive` -\tStarts an interactive learning session to create new training data by chatting to your assistant.\n", |
| 104 | + "- `rasa visualize` - Generates a visual representation of your stories.\n", |
| 105 | + "- `rasa train` - Trains a model using your NLU data and stories, saves trained model in `./models`.\n", |
| 106 | + "\n", |
| 107 | + "**Important Note on `rasa train`:**\n", |
| 108 | + "- If you have existing models in your directory (under models/ by default), only the parts of your model that have changed will be re-trained. For example, if you edit your NLU training data and nothing else, only the NLU part will be trained.\n", |
| 109 | + "- If you want to train an NLU or dialogue model individually, you can run `rasa train nlu` or `rasa train core`. If you provide training data only for one one of these, rasa train will fall back to one of these commands by default.\n", |
| 110 | + "\n", |
| 111 | + "### **Important Terminology**\n", |
| 112 | + "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." |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + "cell_type": "markdown", |
| 124 | + "id": "ba868f2e-aa40-4a5c-b7a2-f62e69021d88", |
| 125 | + "metadata": {}, |
| 126 | + "source": [ |
| 127 | + "## **Building the First RASA Project**\n", |
| 128 | + "\n", |
| 129 | + "1. **Create a new RASA Project:**\n", |
| 130 | + "```bash\n", |
| 131 | + "rasa init # Initialize a new project\n", |
| 132 | + "```\n", |
| 133 | + "2. **Understand the Project Structure:**\n", |
| 134 | + "- `data/nlu.yml`: Contains NLU training data.\n", |
| 135 | + "- `data/stories.yml`: Contains conversation training data.\n", |
| 136 | + "- `domain.yml`: Defines the domain of the assistant.\n", |
| 137 | + "- `config.yml`: Configures the NLU and Core pipelines.\n", |
| 138 | + "- `actions.py`: Defines custom actions.\n", |
| 139 | + "\n", |
| 140 | + "3. **Running Your First RASA Bot:**\n", |
| 141 | + "```bash\n", |
| 142 | + "rasa train # Train the model\n", |
| 143 | + "rasa shell # Stract the RASA Server\n", |
| 144 | + "```" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "markdown", |
| 149 | + "id": "0aa4529f-1fc3-46dc-b2dc-9c1ecdc71a4e", |
| 150 | + "metadata": {}, |
| 151 | + "source": [ |
| 152 | + "### **Creating NLU Training Data**\n", |
| 153 | + "\n", |
| 154 | + "Define intents and entities in `data/nlu.yml`:\n", |
| 155 | + "```yaml\n", |
| 156 | + "version: \"2.0\"\n", |
| 157 | + "nlu:\n", |
| 158 | + "- intent: greet\n", |
| 159 | + " examples: |\n", |
| 160 | + " - hello\n", |
| 161 | + " - hi\n", |
| 162 | + " - hey\n", |
| 163 | + "\n", |
| 164 | + "- intent: book_flight\n", |
| 165 | + " examples: |\n", |
| 166 | + " - I want to book a flight to [Paris](location)\n", |
| 167 | + " - Book a flight to [New York](location)\n", |
| 168 | + "```\n", |
| 169 | + "\n", |
| 170 | + "For every **new intent** created, add it in `domain.yml`. \n", |
| 171 | + "\n", |
| 172 | + "```yaml\n", |
| 173 | + "intents:\n", |
| 174 | + " - greet\n", |
| 175 | + " - book_flight\n", |
| 176 | + "```" |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "markdown", |
| 181 | + "id": "6be786eb-5275-4587-b0a1-a81e30fbf5c3", |
| 182 | + "metadata": {}, |
| 183 | + "source": [ |
| 184 | + "### **Customizing Dialogue Management**\n", |
| 185 | + "\n", |
| 186 | + "Define stories in `data/stories.yml`:\n", |
| 187 | + "```yaml\n", |
| 188 | + "version: \"2.0\"\n", |
| 189 | + "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", |
| 201 | + "```\n", |
| 202 | + "\n", |
| 203 | + "Define actions, slots and responses in `domain.yml`:\n", |
| 204 | + "```yaml\n", |
| 205 | + "version: \"2.0\"\n", |
| 206 | + "intents:\n", |
| 207 | + " - greet\n", |
| 208 | + " - book_flight\n", |
| 209 | + " - inform\n", |
| 210 | + "\n", |
| 211 | + "entities:\n", |
| 212 | + " - location\n", |
| 213 | + "\n", |
| 214 | + "slots:\n", |
| 215 | + " location:\n", |
| 216 | + " type: text\n", |
| 217 | + "\n", |
| 218 | + "responses:\n", |
| 219 | + " 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", |
| 227 | + "```" |
| 228 | + ] |
| 229 | + }, |
| 230 | + { |
| 231 | + "cell_type": "markdown", |
| 232 | + "id": "75c84f74-cee5-4cd0-8652-209b93329764", |
| 233 | + "metadata": {}, |
| 234 | + "source": [ |
| 235 | + "## **RASA Developer Certificate Exam**\n", |
| 236 | + "\n", |
| 237 | + "The Rasa Developer Certification exam is designed to provide a credential that shows that you are a Rasa developer who has an understanding of the Rasa framework and best practices in chatbot development.\n", |
| 238 | + "\n", |
| 239 | + "#### **Exam Syllabus**\n", |
| 240 | + "You should be able to:\n", |
| 241 | + "\n", |
| 242 | + "- Create a new assistant\n", |
| 243 | + "- Add a new response\n", |
| 244 | + "- Add a new intent\n", |
| 245 | + "- Add a new entity\n", |
| 246 | + "- Add a new slot\n", |
| 247 | + "- Add a new story\n", |
| 248 | + "- Add a form\n", |
| 249 | + "- Add FAQ's\n", |
| 250 | + "- Add a test story\n", |
| 251 | + "- Add a rule\n", |
| 252 | + "- Correctly use entities and intents\n", |
| 253 | + "\n", |
| 254 | + "You should know:\n", |
| 255 | + "\n", |
| 256 | + "- The most commonly-used command line interface (CLI) commands\n", |
| 257 | + "- What files make up a Rasa assistant and what information is contained in each\n", |
| 258 | + "- What Rasa X is\n", |
| 259 | + "- What CDD is and why it's important\n", |
| 260 | + "- The differences between slots and entities\n", |
| 261 | + "- How and why to test your assistant\n", |
| 262 | + "- How to interpret model evaluation\n", |
| 263 | + "- What confidence means and what it's used for\n", |
| 264 | + "\n", |
| 265 | + "#### **Exam Link**\n", |
| 266 | + "**[Click here](https://learning.rasa.com/certification-study-guide/)** to get the link to certification exam." |
| 267 | + ] |
| 268 | + } |
| 269 | + ], |
| 270 | + "metadata": { |
| 271 | + "kernelspec": { |
| 272 | + "display_name": "Python 3 (ipykernel)", |
| 273 | + "language": "python", |
| 274 | + "name": "python3" |
| 275 | + }, |
| 276 | + "language_info": { |
| 277 | + "codemirror_mode": { |
| 278 | + "name": "ipython", |
| 279 | + "version": 3 |
| 280 | + }, |
| 281 | + "file_extension": ".py", |
| 282 | + "mimetype": "text/x-python", |
| 283 | + "name": "python", |
| 284 | + "nbconvert_exporter": "python", |
| 285 | + "pygments_lexer": "ipython3", |
| 286 | + "version": "3.9.13" |
| 287 | + } |
| 288 | + }, |
| 289 | + "nbformat": 4, |
| 290 | + "nbformat_minor": 5 |
| 291 | +} |
0 commit comments