Skip to content

Rule-based NLP chatbot using TF-IDF & cosine similarity over 1000+ real-world QnA — fast, offline & LLM-free.

Notifications You must be signed in to change notification settings

masfaatanveer/QnA-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🤖 QnA-Chatbot

A Fast & Lightweight Rule-Based NLP Chatbot using TF-IDF

Get instant answers from a smart chatbot trained on 1000+ real-world questions — without any heavy LLMs!
Built using Python, TF-IDF, cosine similarity and deployed via Streamlit.


🧠 How It Works

  • Reads a CSV of 1000+ questions and answers across various topics
  • Converts user input + stored questions into TF-IDF vectors
  • Uses cosine similarity to find the best-matching response
  • If no match crosses a confidence threshold, returns a fallback message
  • Runs inside a clean Streamlit UI for fast and easy use

🗂 Example Topics in Dataset

  • General Knowledge
  • Science & Technology
  • Programming
  • Health & Wellness
  • Islamic / Spiritual
  • Education
  • FAQs, Casual Chat, and more...

⚙️ Run the Chatbot Locally

  1. Clone the repo
git clone https://github.com/masfaatanveer/QnA-Chatbot.git
cd QnA-Chatbot
  1. Install dependencies
pip install -r requirements.txt
  1. Run the app
streamlit run app.py
  1. Chat away!
    Ask anything similar to the dataset — the bot will respond instantly.

📁 Project Structure

📁 QnA-Chatbot/
├── app.py                # Streamlit UI + chatbot logic
├── chatbot.py            # Core TF-IDF + cosine chatbot class
├── data/
│   └── qna_dataset.csv   # 1000+ question-answer pairs
├── demo.mp4              # Optional demo file for reference
├── requirements.txt
└── README.md

🔥 Why This Project?

  • ⚡ Super lightweight — no LLMs or APIs needed
  • 🚀 Fast inference with 1000+ real QnA samples
  • 🧩 Easy to customize — just replace the CSV!
  • 💬 Works offline — perfect for internal, embedded, or edge use
  • 🧠 Great for demos, AI interviews, chatbot courses, or helpdesk bots

💡 Future Ideas

  • Add feedback system to improve accuracy
  • Upgrade to contextual memory (or RAG-based)
  • Export chat history / save sessions
  • Add voice (speech-to-text) support

🌐 Connect & Demo

🎥 See this project in action on my LinkedIn:
🔗 Chatbot Demo + Post


🙋‍♂️ Created By

Masfa Dhillon
GitHubLinkedIn


📄 License

MIT License — Free to use, modify, and deploy with credit.


About

Rule-based NLP chatbot using TF-IDF & cosine similarity over 1000+ real-world QnA — fast, offline & LLM-free.

Topics

Resources

Stars

Watchers

Forks

Languages