Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– NLP Intent-Based Chatbot

An intelligent intent-based chatbot developed using Natural Language Processing (NLP) and Machine Learning. The chatbot classifies user queries into predefined intents using TF-IDF Vectorization and Logistic Regression, then responds with an appropriate predefined reply through an interactive Streamlit interface.


๐Ÿ“– Overview

Conversational AI has become an essential component of modern software systems. However, not every chatbot requires large language models such as ChatGPT or Gemini. For many domain-specific applications, an intent-based chatbot provides a lightweight, efficient, and accurate solution.

This project demonstrates how traditional Natural Language Processing techniques can be combined with Machine Learning to build a chatbot capable of understanding user intentions and generating appropriate responses.

Instead of generating responses dynamically, the chatbot identifies the user's intent from predefined training examples and returns the most relevant response.


๐ŸŽฏ Objectives

  • Build an intent-based chatbot using NLP techniques.
  • Understand text preprocessing and feature extraction.
  • Implement text classification using Machine Learning.
  • Develop an interactive chatbot interface.
  • Store conversation history for future reference.

โœจ Features

  • Intent-based conversational chatbot
  • Natural Language Processing using TF-IDF
  • Logistic Regression text classification
  • Interactive Streamlit interface
  • Conversation history logging
  • CSV-based chat history storage
  • Randomized responses for each intent
  • Lightweight and fast inference

๐Ÿ—๏ธ System Architecture

User Input
      โ”‚
      โ–ผ
Text Preprocessing
      โ”‚
      โ–ผ
TF-IDF Vectorization
      โ”‚
      โ–ผ
Logistic Regression Model
      โ”‚
      โ–ผ
Intent Prediction
      โ”‚
      โ–ผ
Retrieve Response from intents.json
      โ”‚
      โ–ผ
Display Response
      โ”‚
      โ–ผ
Store Conversation in CSV

๐Ÿ”„ Workflow

  1. User enters a message.
  2. The text is converted into TF-IDF feature vectors.
  3. Logistic Regression predicts the most probable intent.
  4. The predicted intent is matched with the corresponding responses in intents.json.
  5. One response is selected randomly.
  6. The chatbot displays the response.
  7. The conversation is stored in a CSV file with timestamps.

๐Ÿง  How It Works

Unlike generative AI models, this chatbot does not generate new responses.

Instead, it follows an Intent Classification Pipeline:

User Question

โ†“

TF-IDF Feature Extraction

โ†“

Logistic Regression

โ†“

Intent Prediction

โ†“

Select Random Response

โ†“

Display Response

๐Ÿ“‚ Project Structure

Chatbot/
โ”‚
โ”œโ”€โ”€ chatbot.py
โ”œโ”€โ”€ intents.json
โ”œโ”€โ”€ nltk_data/
โ”œโ”€โ”€ chat_log.csv
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿ“š NLP Pipeline

1. Intent Dataset

The chatbot is trained using an intents.json file.

Each intent contains:

  • Tag
  • Example patterns
  • Multiple responses

Example:

{
  "tag": "greeting",
  "patterns": [
    "Hello",
    "Hi",
    "Good Morning"
  ],
  "responses": [
    "Hello!",
    "Hi there!",
    "Welcome!"
  ]
}

2. Text Vectorization

Raw text cannot be processed directly by Machine Learning models.

The chatbot converts text into numerical features using TF-IDF Vectorization.

TF-IDF assigns higher importance to words that are important within a sentence while reducing the importance of common words.


3. Model Training

The chatbot uses Logistic Regression as the classification algorithm.

Training process:

Training Patterns

โ†“

TF-IDF Vectorization

โ†“

Feature Matrix

โ†“

Logistic Regression

โ†“

Trained Intent Classifier


4. Intent Prediction

When the user enters a message:

  • Convert text into TF-IDF features.
  • Pass features to Logistic Regression.
  • Predict the intent.
  • Retrieve matching responses.
  • Display one randomly selected response.

๐Ÿค– Why Logistic Regression?

Logistic Regression is well-suited for intent classification because:

  • Fast to train
  • Computationally efficient
  • Works well with TF-IDF features
  • Excellent baseline for text classification
  • Easy to interpret

๐Ÿ“– Why TF-IDF?

TF-IDF transforms text into numerical vectors while preserving the importance of meaningful words.

Advantages:

  • Lightweight
  • Fast
  • Easy to implement
  • Performs well on small datasets
  • Excellent for intent classification

๐Ÿ’ป Technology Stack

Programming Language

  • Python

Machine Learning

  • Scikit-learn

NLP

  • NLTK
  • TF-IDF Vectorizer

Model

  • Logistic Regression

Frontend

  • Streamlit

Data Storage

  • CSV

๐Ÿ“ˆ Conversation Logging

Every conversation is automatically stored inside:

chat_log.csv

Each record contains:

  • User Input
  • Chatbot Response
  • Timestamp

This enables future analysis and conversation tracking.


๐Ÿš€ Installation

Clone the repository

git clone https://github.com/vishayadav/Chatbot.git

Navigate to the project

cd Chatbot

Install dependencies

pip install -r requirements.txt

Run the application

streamlit run chatbot.py

๐Ÿ”ฎ Future Improvements

Possible enhancements include:

  • Deep Learning-based intent classification
  • Transformer models (BERT/DistilBERT)
  • Named Entity Recognition (NER)
  • Context-aware conversations
  • Multi-turn dialogue management
  • Voice-based interaction
  • Integration with LLM APIs
  • Database-backed conversation history

๐Ÿ“š Learning Outcomes

Through this project, I gained practical experience in:

  • Natural Language Processing
  • Intent Classification
  • Text Vectorization
  • TF-IDF
  • Logistic Regression
  • Streamlit Application Development
  • Conversation Logging
  • Machine Learning Workflow

โš ๏ธ Limitations

  • Cannot answer questions outside predefined intents.
  • Does not generate new responses.
  • No contextual memory between conversations.
  • Performance depends on the quality of training patterns.
  • Limited scalability compared to modern LLM-based chatbots.

๐Ÿ‘ฉโ€๐Ÿ’ป Author

Visha Yadav

Computer Engineering Student

Passionate about AI, Machine Learning, NLP, and Software Engineering.


About

Intent-based NLP chatbot using TF-IDF and Logistic Regression to classify user queries and deliver intelligent responses.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages