The Chatbots and intelligent virtual assistants market is projected to grow at a CAGR of 22% between 2020 and 2025, potentially reaching nearly $14 billion by 2025.š
When it comes to the world of chatbots š¤, not all the bots are the same. Think of the simplest chatbots, those that stick to set scripts and respond to exact phrasesālike an FAQ section come to life. These are rule-based bots and can be helpful but often feel a bit, well, robotic.
Then there are retrieval-based bots that look for the best match from pre-existing responses, leveraging machine learning to be more flexible with language. These are good but still limited, especially if youāre looking for real interaction and multi-turn conversations.
Finally, we have conversational AI botsāthe real stars of the chatbot world š. They go beyond just answering questions; theyāre context-aware, meaning they can remember details, adapt based on the conversation, and feel more like a human chat. And this is where Rasa comes in. With Rasa, you can build a bot thatās genuinely smart, customizable, and responsive to individual users.
š¤ What is Rasa?
Rasa is an open-source framework for building chat and voice-based AI assistants. Rasa lets us control every step of the chatbot's workflow.
Behind the Scenes: How Rasaās Conversational AI Works
Hereās a glimpse of whatās happening under the hood with Rasa:
Intent Recognition: The bot uses machine learning to identify user intent (e.g., ācheck balanceā) based on trained examples, allowing it to interpret even varied phrasings.
Entity Extraction: Rasa recognizes specific details, or entities (like āaccount balanceā or āloan eligibilityā), from the userās input to respond accurately.
Dialogue Management: Rasaās dialogue policies and stories control the conversation flow, remembering previous interactions and guiding the bot to respond contextually.
What Youāll Build in This Tutorial
In this tutorial, weāll bring these elements together to create a financial AI chatbot capable of assisting with common banking inquiries. By the end, youāll have the skills to expand this bot further, adapt it to specific use cases, and understand the core of conversational AI.
āØLetās get started!š
Step 1: Set Up Your Project
Letās start by creating a new Rasa project. Open your terminal and from your project directory, type:
rasa init --no-prompt
This command sets up the files weāll be working with, like nlu.yml for defining intents and stories.yml for conversation flows.
Step 2: Defining Intents
Think of an āintentā as what the user wants to do. For example, when someone says āHey!ā they want to greet the bot. Letās add a few intents to teach Rasa how to recognize them:
Open data/nlu.yml and add some examples:
- intent: greet
examples: |
- hello
- hi there
- hey
Great job! Now, letās train the model so Rasa can understand these intents. In your terminal, run:
rasa train
Step 3: Creating Conversation Flows
Next, weāll map out conversation flows. Think of it as scripting a conversationāwhat should the bot say when someone greets it?
a. Open data/stories.yml and add this story
- story: greet path
steps:
- intent: greet
- action: utter_greet
Now, the bot will respond with āutter_greetā whenever someone says hello!
Step 4: Defining Responses
Letās make the bot sound friendly! In domain.yml, define what āutter_greetā should say:
responses:
utter_greet:
- text: "Hello! How can I assist you today?"
Feel free to get creative with responsesāthis is your chatbot, after all!
Real-World Case Study: Finance Chatbot
Letās take this up a notch. Imagine a bank chatbot that can answer questions about account balances and loan eligibility.
a. Add a check_balance intent in nlu.yml:
- intent: check_balance
examples: |
- What is my account balance?
- Show my balance
- intent: loan_eligibility
examples: |
- Am I eligible for a loan?
- Can I get a loan?
- Whatās my loan eligibility?
In nlu.yml, weāre teaching the bot to recognize user intents: if they ask about balance, itās check_balance; for loans, itās loan_eligibility. This setup helps the bot understand and respond accurately
b. Define a Custom Action in actions/actions.py to handle balance requests:
from rasa_sdk import Action
class ActionCheckBalance(Action):
def name(self):
return "action_check_balance"
def run(self, dispatcher, tracker, domain):
# Example logic for retrieving balance
balance = "$10,000"
dispatcher.utter_message(text=f"Your balance is {balance}.")
return []
class ActionCheckLoanEligibility(Action):
def name(self):
return "action_check_loan_eligibility"
def run(self, dispatcher, tracker, domain):
# Placeholder logic for loan eligibility
eligibility_status = "You're eligible for a loan up to $50,000!"
dispatcher.utter_message(text=eligibility_status)
return []
In the above code, we set up a custom action called ActionCheckBalance for the bot. When a user asks about their balance, this action responds with a set balance of "$10,000." Think of it as a placeholderālater, you can link it to actual account data for live results!
For eligibility status, I have set to respond with "You're eligible for a loan up to $50,000!" as a placeholder. Similar to account balance action, you can also replace it with actual calculations or criteria.
c. In stories.yml, add this flow for the balance check:
- story: check balance path
steps:
- intent: check_balance
- action: action_check_balance
- story: check loan eligibility path
steps:
- intent: loan_eligibility
- action: action_check_loan_eligibility
In the above stories.yml, we're mapping user paths: if they ask for a balance, the bot triggers action_check_balance; for loans, it triggers action_check_loan_eligibility. This guides the botās responses based on user intent!
Step 5: Testing and Fine-Tuning
Time to test it! In your terminal, run:
rasa interactive
This lets you simulate real conversations and adjust responses on the go.
š Congratulations! Your chatbot can now handle basic finance queries.
Remember, the world of conversational AI is constantly evolving, and every tweak you make to your bot brings it closer to a more natural, human-like interaction. So, keep experimenting, stay curious, and donāt be afraid to explore new possibilities with Rasa and conversational AI. Who knows? This might just be the start of your very own AI-driven customer experience journey š±.
Scaling Up: Going Beyond Basics
For those ready to dive deeper:
- Deploy to Multiple Platforms: Consider integrating with Slack/MS Teams or a custom API for a broader reach.
- Advanced Response Customization: Add Rasa custom pipelines or integrate with external databases.
More Recommended Reading on this topic
- Rasa Documentation for in-depth guidance.
- Conversational Design Best Practices for user-centric tips.
Happy building!š Don't forget to check out my other articles on AIHandsOn Series for more interesting projects on AI! š
š You can also learn more about my work and projects at https://santhoshvijayabaskar.com