CS312 Prolog Chatbot

From UBC Wiki

Authors: Shiv Vashisht, Kabir Chattopadhyay, Nam Hee Gordon Kim

What is the problem?

Our goal is to determine whether Prolog is a suitable platform for creating a limited-scope chatbot. As it is known, a chatbot essentially parses a natural language input (e.g. what day is it?) and provides a response to the user. The response that the chatbot produces is expected to make sense in context of the user's input. Usually, how these chatbots are implemented is through identifying keywords in the natural language and then selecting appropriate response phrases after combining them using a natural language interface. We plan to research existing implementations of chatbots in Prolog (e.g Eliza) and attempt to build our own so that we can determine whether Prolog is a feasible language.

What is the something extra?

In our class examples and within the scope of this course, we have only worked with programs with finite queries. In other words, we only asked questions of the natural language interface - however, in a chatbot, the possible questions a user can ask are quite ambiguous and in fact, the chatbot might just ask the user a question. Further, the goal is to provide a response that isn't arbitrary but makes sense in terms of the context of the user's input. We want to use keywords from the input to identify a subject that the user is discussing and then choose a response for that particular subject.

This implementation provides the something "extra" by going beyond just querying a static knowledge base and instead, adding to the knowledge base and generating the chatbot's output based off of the user's input.

What did we learn from doing this?

Overall, while the overall process of creating a chatbot in Prolog was initially quite simple, there were still a number of obstacles we ran into along the way. First of all, we had difficulty getting the bot to receive natural language phrases. Rather than having comma separated words as sentences, we had to parse full sentences into sections. The second obstacle we faced was getting the chatbot to respond to the prompts given. This essentially meant that we had to build a large enough knowledge base such that it could cover every single possible scenario – this was pretty much an impossible task. To find our way around it, we had to limit the scope of the chatbot and put some restrictions in terms of what it was capable of answering. As such, we stuck to the scope of CPSC 312 this term.

Further, an important capability of a chatbot is to retain context such that it can maintain a conversation and get additional information from a user. To achieve this capability, we added functionality that allowed certain questions to add information to the database using assert statements. This idea was essentially based on the concept of forward chaining as later phrases were able to know what the current point of discussion is. 

All in all, we learned that a decent, capable chatbot is feasible to create and by looking at our code, it can clearly be done relatively simply and concisely. Prolog provides unmatched capability in terms of pattern matching and NLP that is able to help implement various situations, such as User Input/Output, efficiently. In our case, we were able to implement this with a limited scope, however, with a large knowledge base that continuously grows, anything is truly possible with Prolog.

Link to code: