How Do Chatbots Work?
They might seem complicated at first, but building computer bots is surprisingly easy. Of course, building a sophisticated bot that’s able to perform complex interactions is much more difficult. Chatbots use natural language processing (NLP) technology to understand words and phrases, and complex bots use artificial intelligence (AI) technology, as well.
April 18, 2018
Simple chatbots, or bots, are easy to build. In fact, many coders have automated bot-building processes and templates. The majority of these processes follow simple code formulas that the designer plans, and the bots provide the responses coded into it—and only those responses. Simplistic bots (built in five minutes or less) typically respond to one or two very specific commands.
However, if you’re trying to develop a sophisticated bot that can understand more than a couple of basic commands, you’re heading down a potentially complicated path. More elaborately coded bots respond to various forms of user questions and responses. Wondering how bots work? They’re typically “trained” on databases of thousands of words, queries, or sentences so that they can learn to detect lexical similarity. A good e-commerce bot “knows” that trousers are a kind of pants (if you’re in the United States), though this is beyond the comprehension of a simple, untrained bot.
Smart bots take more time to develop, code, launch, and test, but they’re often a necessity for meeting customer satisfaction goals.
Here’s an example of an easy-to-build bot versus a difficult-to-build one.
Say you want to build a bot that tells the current temperature. The dialogue for the bot only needs coding to recognize and report the requested location and temperature. To do this, you need to think of building computer bots to pull data from the API of the local weather service, based on the user’s location, and to send that data back to the user—basically, a few lines of template code and you’re done.
What if you’re creating a bot for a major online clothing retailer? For starters, the bot will require a greeting (“How can I help you?”), as well as a process for saying its goodbyes. In between, the bot needs to respond to inputs, which could range from shopping inquiries to questions about shipping rates or return policies, and the bot must possess a script for fielding questions it doesn’t understand.
From any point in the conversation, the bot needs to know where to go next. If a user writes, “I’m looking for new pants,” the bot might ask, “For a man or woman?” The user may type, “For a woman.” Does the bot then ask about size, style, brand, or color? What if one of those modifiers was already specified in the query? The possibilities are endless, and every one of them has to be mapped with rules.
Bots are getting smarter
A simple bot might only be programmed with a few specific responses, like our hypothetical temperature bot. But a truly conversational bot needs to possess artificial learning abilities and more developed intents. The more these bots interact with humans, the “smarter” they get. These “smart bots” converse by using different algorithms to solve problems.
Machine learning allows bots to mimic human learning processes. A blend of mathematical codes, commands, rules, and training enables bots to learn from user input and other data inputs, allowing their vocabularies and understandings to grow over time.
Back to our earlier example, if a bot doesn’t know the word trousers and a user corrects the input to pants, the bot will remember the connection between those two words in the future. The more words and connections that a bot is exposed to, the smarter it gets. This process is similar to that of human learning. Our capacity for memory and synthesis is part of what makes us unique, and we’re teaching our best tricks to bots.
Coders are also getting smarter
Humans communicate in natural language. It’s a blend of taught, learned, and invented phonemes mashed together to form meaning. It’s not perfect. In fact, a lot of the time, it doesn’t even make sense—just look at the long list of homophones, homonyms, and homographs in English.
On the other side, computers typically communicate with what is called artificial language. These are programming languages like Python, PHP, and Ruby on Rails, and they run scripts in code to operate. In the past, computers were only able to understand these artificial languages.
With natural language processing (NLP), a bot can understand what a human is asking. The computer translates the natural language of a question into its own artificial language. It breaks down human inputs into coded units and uses algorithms to determine what is most likely being asked of it. From there, it determines the answer. Then, with natural language generation (NLG), it creates a response. NLG software allows the bot to construct and provide a response in the natural language format.
The software is a translator for the bot. A user asks a question in a natural language. The NLP translates the natural language by breaking down the request into the smallest possible unit of language. For written input, this happens at the word level. For spoken input, this happens at the level of the phoneme, which is a distinct spoken sound.
The NLP system has a wide and varied lexicon to better understand the complexities of natural language. Using an algorithmic process, it determines what has been asked and uses decision trees or slot-based algorithms that go through a predefined conversation path. After it understands the question, the computer then finds the best answer and provides it in the natural language of the user.
Bots will continue to evolve
With machine learning and natural language processing, bots have advanced to the complexity of virtual assistants, like Siri, Amazon Alexa, and many others emerging from AI developments. Today, any task or question with a finite number of possible responses can theoretically be coded into a bot—and many have.
But, as any human knows, no question or statement in a conversation really has a limited number of potential responses, and this drives how bots work in the modern era. There is an infinite number of ways to combine the finite number of words in a human language to say something. Real conversation requires creativity, spontaneity, and inference. Right now, those traits are still the realm of humans alone. There is still a gamut of work to finish in order to make bots as person-centric as Rogerian therapists, but bots and their creators are getting closer every day.