This project demonstrates how to build an intelligent chatbot using Python, TensorFlow, and Natural Language Processing (NLP). The chatbot is trained to respond to various user queries based on predefined intents.
- NLP-based intent recognition using
nltk - Neural Network classifier using
TensorFlow / Keras - Interactive terminal chat interface
- Easily customizable intent dataset (
intents.json) - Persistence using model/tokenizer/encoder saving
- Lightweight Flask integration possible (for future deployment)
📁 chatbot-ml/
│
├── intents.json # Intents dataset (patterns + responses)
├── chatbot.ipynb # Jupyter notebook with all training code
├── tokenizer.pickle # Saved tokenizer for inference
├── label\_encoder.pickle # Saved label encoder
├── chat\_model/ # Saved TensorFlow model
└── README.md # You're reading this!
Install the required packages:
pip install tensorflow==2.3.1
pip install nltk==3.5
pip install colorama==0.4.3
pip install numpy==1.18.5
pip install scikit-learn==0.23.2
pip install Flask==1.1.2-
Data Preparation
- Load and process the
intents.jsonfile. - Use
LabelEncoderto encode intent tags. - Tokenize and pad text using Keras tokenizer.
- Load and process the
-
Model Training
-
Create a simple feed-forward neural network with:
- Embedding Layer
- GlobalAveragePooling1D
- Dense Layers
-
Train for 500 epochs.
-
-
Model Saving
- Save the trained model (
chat_model) - Save the tokenizer and label encoder for inference.
- Save the trained model (
-
Chat Function
- Load saved model and tokenizer.
- Predict intent of the user's message.
- Reply with an appropriate response.
User: Hi
ChatBot: Hello!
User: What is your name?
ChatBot: I'm RISHU, your virtual assistant.
User: I forgot my password
ChatBot: Please click 'Forgot Password' on the login page to reset it.
User: quitYou can add or modify intents inside intents.json like:
{
"tag": "greeting",
"patterns": ["Hello", "Hi", "Hey"],
"responses": ["Hi there!", "Hello!", "Hey!"]
}Don't forget to re-train the model after editing!
- Add support for multiple languages
- Integrate with Flask API
- Deploy on web/mobile
- Contextual conversation memory
Built using:
This project is for educational purposes and is open-source. Feel free to fork and improve!