DIY ChatBot: QnA Bot with Flask and Sklearn

Yogesh Ingale
Nov 3, 2019 · 2 min read

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 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\ 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\

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

Chatbot in Action:

Bot in Action

Feedback Mechanism:

Bot with a snapshot of feedback

Future scopes:

  • You can add Database for a large number of QnA pairs.

For more DIY Chatbots article Click Here.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade