A conversational AI chatbot built with Python, Flask, NLTK, and Keras. The chatbot uses Natural Language Processing (NLP) to understand user inputs and a Deep Learning model to classify intents and provide appropriate responses.
- Intent Classification: Uses a deep learning model to accurately classify user intents.
- Natural Language Processing: Employs NLTK for tokenization, lemmatization, and bag-of-words creation.
- Web Interface: Simple and intuitive web interface powered by Flask.
- Configurable: Easy to update intents and retrain the model via
config.py. - Error Handling: Graceful fallback response when intent is not recognized.
| Technology | Description |
|---|---|
| Python | Core programming language |
| Flask | Web framework for the server and API |
| NLTK | Natural Language Toolkit for text processing |
| Keras / TensorFlow | Deep learning framework for the classification model |
-
Clone the repository:
git clone https://github.com/anYoneo/chatbot cd chatbot -
Install the required dependencies:
pip install -r requirements.txt
Before running the app for the first time, or after updating data.json, train the model:
python training.pyThis generates model.h5, texts.pkl, and labels.pkl.
python app.pyOpen your browser at http://localhost:5000
chatbot/
├── app.py # Main Flask application and NLP prediction logic
├── config.py # Configuration settings (threshold, paths, debug)
├── training.py # Script to train the Keras model
├── data.json # Training data (intents, patterns, responses)
├── requirements.txt # Python dependencies
├── README.md # Project documentation
├── .gitignore # Git ignore rules
├── static/ # Static files (CSS, JS, images)
└── templates/ # HTML templates
└── index.html # Main chat UI
(Binary files model.h5, texts.pkl, labels.pkl are generated after training)
Training Phase:
- Reads
data.jsoncontaining intents (tags, patterns, responses) - Tokenizes & lemmatizes patterns using NLTK
- Creates Bag of Words representation
- Trains a feedforward neural network (Keras) to classify intents
- Saves model + vocabulary to disk
Inference Phase:
- User sends message via Flask web UI
- Message is tokenized, lemmatized → Bag of Words
- Keras model predicts intent probability
- If probability >
ERROR_THRESHOLD(0.25): best intent is chosen - Random response for the intent is returned to user