Question

What framework can I start with to create a simple chatbot? the focus of the bot is very limited(for my project management website http://ayeboss.com).

One can compare it with SIRI on iPhone. I want to create a simple "answering" chat which will answer questions like "give me all completed tasks so far" or "show me last completed task" or "show|list|give me my pending tasks" etc. After user asks the question I want to present the data to the user

As of now I am creating a regex dictionary of possible questions and if there is no match then I do a lucene search to find the nearest match. Am I doing it right?

Was it helpful?

Solution

This is a NLP task, and for building a system like this require lot of R&D. You can start by building a set of question that might be asked. Analyzing the questions and coming up with word patterns for each type of question. The next step would be to transform the English sentence into some form of formal structure( maybe SQL or lambda calculus). The backend DB should have the data stored in it which can be queried by the formal language.

The main problem lies in converting the English sentence to a formal language. You can start with regex and progress to make it more complex by checking Part of Speech, Syntactic structure of input sentences. Check out NLTK package for doing NLP tasks.

OTHER TIPS

Typically, chatbots within a narrow field like yours typically rely on 2 important concepts:

  • Intent detection: identifying what the user is requesting
  • Entity Extraction: Identifying entites in the users request. For instance in a flight reservation bot examples of entities are the source, destination and travel dates. In a weather bot the entities can be the desired date for the weather or the location where the weather is required.

For your specific type of chatbot, which has a definite goal of retrieving list of completed tasks and retrieving the last completed task. To develop this, you need to define the intents of interest. From you examples we can easily define 2 intents:

  • COMPLETED_TASKS_REQUEST
  • LAST_COMPLETED_TASK

Based on this 2 intents, there is really no entity to be detected. You simply query your service API to retrieve the requested information in each scenario.

The next phase will be to train a classifier to identify the intents. This can be done by getting some sample sentences for each request type and training over those.

The flow is then reduced to the following:

  1. Bot receives message
  2. Bot identifies intent
  3. Bot extracts relevant entities (if required)
  4. If intent is recognised bot queries data source to retrieve answer else bot complains it doesn't understand the request. Alternatively if bot needs an entity to complete request, bot asks user to provide the information and completes its task. This is usually called a slot based approach. You can read more on how a Dialog Manager works.

Note that if you're not into Machine Learning or NLP you can easily train an intent detector on platforms like wit.ai or api.ai and the entity classification part of this task will be reduced to simple http API requests. Though when building genuinely complicated or sophisticated bots it is almost always better to build your own models since you can have full control and can handle edge cases better. Platforms like wit.ai or api.ai generally need to perform well across multiple fields while you can focus on making yours an expert in task management.

Hope this helps.

PS: To make your bot more interesting we can add one more intent like retrieving the status of a specific task given the id. E.g a user can ask what is the status of task 54. This intent can be called: TASK_STATUS_REQUEST. In this example, the intent has an entity which is the id of the requested task so you will need to extract that :)

On top of chat bot library, you can integration instant messaging library like Hyphenate to enable chat bot for mobile and web communication.

Here're few simple steps:

  1. Hyphenate Console: Create a chatbot entity by sign up an account at Hyphenate console (console.hyphenate.io) to give your chatbot an identity and a voice by creating Hyphenate IM account for the bot.
  2. Platform SDK: Integrate your app (iOS, Android, or Web) with Hyphenate IM services and open source UI library.
  3. Webhooks (event callback): Set up Hyphenate webhooks to receive the messages from the user that push to your developer backend, then process it in with your chatbot AI library.
  4. Backend REST API: push chatbot's messages to the user via REST APIs provided by Hyphenate from your developer backend.
  5. Hooray! Webhooks + backend REST API = relay messages between chatbot and user.

http://docs.hyphenate.io/docs/chat-bot-integration

You can use Microsoft NLP frameworks which are pretty straight forward and easy to use for beginners. Also was earlier know as LUIS, it's one of the Cognitive services that Microsoft provides. It's basically a combination of API calls.

Not sure which language you are familiar with, but in Java you can do it using Apache OpenNLP library. This is a very good & easy to use library for natural language processing. To give very basic approach, you can break sentences & tokenize them into words. Then you can lemmatize words to get them to basic word forms. Then you can classify or categorize them using categorizer with proper training data. better the training, smarter the chat bot. Also you can select categories to make chat bot have conversation in more engaging way. Here is a very good article with detailed example & demo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top