Build your First Chatbot in three minutes

30 sec explanation of how Chatbots work

Whether you’re a data scientist, data analyst, or software engineer; and whether you have a strong handle on NLP tools and approaches, if you’re here, you’ve likely wondered how a chatbot works and how to build one, but haven’t ever had the need or chance. Well… you’re here now, so lets get it done.

Most people can chatbot

You’ll be surprised to find you’re likely familiar with what goes into creating your own chatbot

User cases?

It may be to query simple database, make an order, reservation, customer service, and much more. We interact with chatbots every day.

What’s on the inside?

Chatbots are all about what’s called a rule matching engine.

In the simplest form; that pretty much means that when you get a message, what do you do with it?

One way you could do this is just by repeating back what was originally typed. While it seems overly simple and uninteresting, this idea serves as a good foundation before you branch into more complexity with your chatbot.

Lets get our hands dirty

def parrot_talk(incoming_message):
    bot_response = "Hi, my name is Randy the Parrot, you said: " + message
    return bot_response
print(parrot_talk("hello!"))

Obviously that’s a simple example, lets take it up a notch.

responses = {
     "Hello": "Hey! How can I help you?",
     "I need a refund": "I'm happy to help, can you give me more detail?"
 }

def respond(message):
     if message in responses:
         return responses[message]
 respond("I need a refund?")

Similar to what you saw the first time, here is a customer service chatbot. What we’re doing in the above dictionary is establishing keys that should relate to what our customers might say… those keys then map to an appropriate response.

Now obviously the limitation here is that it would require the message to be exactly the same as the key in the dictionary.

We can very quickly become far rigorous, using things like regular expressions on any given message, creating a flag to indicate the presence of various terms in the text & then keying off of that flag to populate our response.

To take it even further, we could deploy ML algorithms that could predict whether or not a message falls under a given intent or topic which we could then map back to the dictionary of appropriate responses.

Challenges

Have you ever seen the auto responses in linkedin? You should try to have a conversation by just tapping those prompts… beyond being fun, it’s an interesting exploration in the sophistication as well as the lack thereof. Among the toughest things for chat bots is the ability to track the state of any given conversation, which will be very obvious once you go and have that chat in linkedin.

Conclusion

Chatbots are surprisingly simple to create at first glance. Come check out more blog posts where we get into more of the nitty gritty of how to make your chatbots far more robust at datasciencelessons.com

Happy Data Science-ing!

Advertisement

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: