By Indu Khatri & Devashish Khatwani.
Lucy is a Bot. What is a Bot? A Chatbot/ Bot/ Talking agent is an artificially intelligent system that communicates via Text Audio, Images etc. We call it a smart buddy who knows the best restaurants, banks, sales agents in your vicinity, can buy products for you and even check public transit disruptions for you! Just talk to it or text it - you'll have your answers. A simple analogy to bots/voice agents is given below:
- Smartphone is equivalent to smart speaker. We are calling this the distribution channel
- Google Play/iOS app store is equivalent to Google Assistant/Siri. We are calling this the platform
- Any app on your phone is equivalent to a Bot. We are calling this the product
This article walks you through a step by step process and comes with starter code for building your own chatbot. In the end we also provide some pointers for folks looking to take this proof of concept to production stage.
How to Build Bot: Here is the 3-steps recipe
1. Design (What to Build):
a. Choose an appropriate use case: This is a really important step of the process as not all use cases benefit from having a voice interface. A general rule of thumb could be that the numbers of steps user needs to take through a visual interface should be more than the number of steps through a voice based interface. On a side note you can also enrich your voice responses with visual cues for the user. We went with three use cases below:
- Helping with special mortgage rates and connecting users to a Bank’s agent
- Helping with purchase of consumer goods online
- Providing service alerts from public transportation
b. Create a persona for the Bot (Pick a voice, Write sample dialogs): Think of this as the branding for your website and company. You may want your brand to stand out as a hipster brand and use words like Swag, YOLO! Etc. to communicate this brand image or if you are a bank you may want a bit more formal dialogues. We went with simple vanilla everyday voice for our bot. A
sample dialogue is given below:
- Wrote dialogs such as “Hi I am Lucy! I can help you with ordering XYZ products” or User would say “I’d like to talk to XYZ Mortgage agent”
c. Design happy path for each use case and dry test the conversation with prospective users to stream line with the flow and identify conversation repair mechanisms. This is one step which you will be coming back to again and again. Your users may not follow the flow you have laid out for them or may even start asking your bot questions for which you don’t even have an API. The good part is that if you have this problem than your bot has already gained the acceptance of your users and now you need to improve it further.
2. Build (How to Build):
a. There are three levels of complexity you will encounter when building bots. The simplest of them is very similar to the dreaded IVR system we all are familiar with. The simplest bot would be a marginal improvement on an IVR system by replacing Yes or No user queries with more conversation querying. For eg, In our bot- Lucy asks whether “you want to buy XYZ products” and user can reply as “Yes” or “Sure” or “I’d love to” etc.
b. The second level is when you create pre-decided entities (functions) for bot. Natural Language Processing helps in extracting pre-decided entities for user utterances. And, then API.AI matches the utterances to the correct function. Here is the list of some of the entities we created for buying XYZ products online use-case. For instance, “ProductCategory” entity would be called when user starts describing/uttering product categories – Hair, Baby etc products.
c. The third level of complexity which is closer to a production level bot will combine Visual, Textual, Multi-device elements. For instance, if you ask the bot “How is the weather in Toronto”. The bot will communicate with paired visual devices such as your TV and display Toronto’s weather on TV screen. Another use case could be: if you ask the bot for directions from point A to B, it would push the response to your smartphone on your Google Maps app.
3. Deploy (How to Deliver):
a. Prototype Deployment: We used Python Flask Assistant package to design the backend of the bot. The middleware for NLP processing and defining the user-flow was designed on GUI interface of API.AI. We finally deployed the bot in a Test Development environment linked to our Google Account on “Actions for Google”. The frontend of our bot was Google Assistant App and we could invoke our Bot by uttering “Ok Google, Talk to Lucy” on our Google Assistant.
b. Production Grade Deployment: When designing a production grade deployment bot, we would need Node.js SDKs of API.AI and Google Assistant. Using these two SDKs, we can define the backend and middleware of the Bot. For deployment we can use Google Cloud function or Amazon Lambda. The frontend will still be Google Assistant but you’ll have to publish the Bot on Google Assistant for it to be available to the public. Below is an example of Deployment Architecture for Production Grade Deployment.Here is the link to the sample GitHub Code: github.com/devashish-khatwani/Lucy
We would encourage you to watch video from Google: youtube.com/watch?v=LHX1GqZuaII
*Disclaimer: Lucy isn’t being used for any commercial purposes.
Indu Khatri is a Technology and Machine Learning Enthusiast. She is Associate Manager of Data Science team at P&G and has been helping Sales & Marketing Leadership Teams to develop Analytics as a competitive advantage. Indu is a keen learner and keeps experimenting with the upcoming Tools & Technologies.
Devashish Khatwani is Manager, Data Science at TD Bank and works on applying advanced machine learning techniques to solve problems such as fraud detection, customer acquisition and operations improvement. In his spare time Devashish tinkers with AWS and Google cloud to develop digital products.
- Chatbots on Steroids: 10 Key Machine Learning Capabilities to Fuel Your Chatbot
- How I Used Deep Learning To Train A Chatbot To Talk Like Me
- The Data Science of NYC Taxi Trips: An Analysis & Visualization