Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to build a chat bot

Tags:

java

chatbot

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?

like image 220
Sap Avatar asked Dec 28 '22 12:12

Sap


2 Answers

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 :)

like image 188
pelumi Avatar answered Dec 30 '22 00:12

pelumi


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.

like image 38
Saurabh Saxena Avatar answered Dec 30 '22 02:12

Saurabh Saxena