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.
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.
- 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.
- 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
User Input
โ
โผ
Text Preprocessing
โ
โผ
TF-IDF Vectorization
โ
โผ
Logistic Regression Model
โ
โผ
Intent Prediction
โ
โผ
Retrieve Response from intents.json
โ
โผ
Display Response
โ
โผ
Store Conversation in CSV
- User enters a message.
- The text is converted into TF-IDF feature vectors.
- Logistic Regression predicts the most probable intent.
- The predicted intent is matched with the corresponding responses in
intents.json. - One response is selected randomly.
- The chatbot displays the response.
- The conversation is stored in a CSV file with timestamps.
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
Chatbot/
โ
โโโ chatbot.py
โโโ intents.json
โโโ nltk_data/
โโโ chat_log.csv
โโโ requirements.txt
โโโ README.md
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!"
]
}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.
The chatbot uses Logistic Regression as the classification algorithm.
Training process:
Training Patterns
โ
TF-IDF Vectorization
โ
Feature Matrix
โ
Logistic Regression
โ
Trained Intent Classifier
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.
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
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
- Python
- Scikit-learn
- NLTK
- TF-IDF Vectorizer
- Logistic Regression
- Streamlit
- CSV
Every conversation is automatically stored inside:
chat_log.csv
Each record contains:
- User Input
- Chatbot Response
- Timestamp
This enables future analysis and conversation tracking.
Clone the repository
git clone https://github.com/vishayadav/Chatbot.gitNavigate to the project
cd ChatbotInstall dependencies
pip install -r requirements.txtRun the application
streamlit run chatbot.pyPossible 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
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
- 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.
Visha Yadav
Computer Engineering Student
Passionate about AI, Machine Learning, NLP, and Software Engineering.