DIY ChatBot: QnA Bot with Flask and Sklearn

Yogesh Ingale
2 min readNov 3, 2019

--

QnA chatbot with a feedback mechanism.

Do you have a list of questions and answer pairs? And want to create chatbot out of it? With the feedback on the answers? This article will help you.

Please keep in mind that this bot will only provide the answers from given QnA pairs. Intent classification, Context generation, Entity extraction, etc is for some other day. For python experts here is the code. Bye. Enjoy! For beginners here how it works:

Follow the instructions from Readme.md to run the app locally, play with the bot and come back to understand what’s happening behind the scenes.

Just for simplicity, the database used here is an Excel sheet, it can be easily replaced with any Relational or Non-Relational database. We are sending the input from the user to the helper function in src\excel_search.py. This is done using /chat route from Flask app.

Now, we need to interpret the question/input and compare it to existing questions provided to the bot(from QnA.xlsx), this can be achieved using Sklearn. Sklearn uses vectorization and provides the maximum confidence value for the best-matched question from the list. (from src\QueryInterpretor.py)

At this point we have the most relevant question from our database, we just need to provide the answer attached to it and ask for feedback. This is done in /chat route fromapp.py.

Chatbot in Action:

Bot in Action

Feedback Mechanism:

Based on a user’s response, we are collecting and storing the feedback in `feedback.xlsx`. We are using the pandas library present in `src\ExcelSearch\update_feedback` to create and update the sheet.

Bot with a snapshot of feedback

Future scopes:

  • You can use any open source chatbot framework to make chatbot more interactive.
  • You can add Database for a large number of QnA pairs.

For more DIY Chatbots article Click Here.

--

--