From UBC Wiki


Authors: Patrick Tseng, Thomas Chisholm, Mike Yoon

What is the problem?

State the general problem. If applicable, tell us what information you will use, e.g., a link to some web site that provides the information you used.

We want to investigate if Prolog is a suitable platform to build a chatbot. A chatbot parses natural language input and provides some response to the user. The response makes sense in context of the user’s input. This can be done using keywords to select response phrases and combining them using a natural language interface. We will research existing Prolog implementations of chatbots and attempt to build one to see if using Prolog is feasible.

What is the something extra?

What is the in-depth aspect you will do? If the problem is related to some other groups, tell us how they fit together. If in doubt, include it.

We need to tokenize the user’s input and categorize it based on what they type. In class we only asked questions of the natural language interface, but in a chat bot the user might input something that isn’t a question, or the bot might ask the user a question. Additionally we want to select a response that makes sense in context of the user’s input. We can use keywords to select a subject that the user is talking about and choose responses for that subject. This goes beyond querying a knowledge base for information and our in-depth aspect will be generating the bots output based on the user’s input

What did we learn from doing this?

(This should be written after you have done the work.) What is the bottom-line? Is logic programming suitable for (part-of) the task? Make sure you include the evidence for your claims.

We ran into various challenges while planning and implementing the chatbot. The first hurdle was getting the bot to accept natural sounding phrases. Rather than having comma separated words as sentences, we had to parse full sentences into sections. We used the readln function discussed in class, and implemented in the natural language parser, as a basis for this. We altered it to behave differently if a subject of conversation is currently set or not. The second step was getting the bot to respond to questions asked. This meant building a large enough KB to cover every possible question - pretty much impossible. One solution was to limit the questions, or put some restriction in the context of the bot. For example, a support chatbot, a small-talk bot, etc. Another one would be to create some sort of self-learning AI, which is definitely out of this scope. We implemented several example responses for a tech support chatbot to demonstrate how a limited scope would make the chatbot more feasible.

Retaining context is also important for a chatbot to maintain a sense of conversation and to get further information from a user. We added functionality so that key questions would add information to the database using assert statements. The idea is based on forward chaining. Later phrases were then able to know what the current ‘topic’ is. Later questions can update the topic. However, not all questions need to have context so there are also paths where nothing is stored.

We implemented categories for different questions, such as greetings, responses to troubleshooting, basic conversational queries and commands. Our in depth aspect was to was to accept natural language as input, and then selecting a response based on the context/query. The natural language part was done using an input reader as described above before tokenizing it and passing it into an altered version of the natural language processor from class. The natural language processor built a list of queries that when proved, construct the response. If the question is a key question, the context is set and the user is asked for more details of their problem. When they provide these details, the subject is set to none, and they are free to ask about another problem. We demonstrated that using our method of separating queries into categories that we can select an answer dynamically that responds to both context and question asked.

In conclusion we believe that it is feasible to create a fully functional chatbot in Prolog, if the domain is restricted and a large knowledge base is created of possible responses or behaviour for the bot to have. We have shown that it is possible to retain context over time in Prolog, and to build conditional responses based on what the current context is. This could be greatly improved by allowing the bot to learn from input that it doesn’t recognize.

References: What is a chat bot - https://en.wikipedia.org/wiki/Chatterbot
ELIZA web demo and source code - http://www.lpa.co.uk/pws_dem4.htm
Forward chaining - https://en.wikipedia.org/wiki/Forward_chaining
Save user input as state - http://stackoverflow.com/questions/23378414/save-argument-into-a-fact-from-user-input