This project involves the development of a chatbot using Artificial Intelligence (AI) and Machine Learning (ML) techniques. The chatbot is trained to understand user queries and respond appropriately based on predefined intents.
training.py
: This file contains the code for training the chatbot model.chatbot.py
: This file contains the code for running the chatbot.
- The training data is stored in a JSON file named
intent.json
, which contains intents along with corresponding patterns and responses. - The NLTK library is used for text processing tasks such as tokenization, lemmatization, and bag-of-words creation.
- Data Loading: The training data is loaded from the
intent.json
file. - Data Preprocessing: Patterns and responses from the intents are extracted and tokenized using NLTK.
- Word Lemmatization: Words are lemmatized to reduce them to their base forms.
- Word Vectorization: The bag-of-words technique is applied to convert words into numerical vectors.
- Model Architecture: A Sequential neural network model is built using Keras. The model consists of dense layers with ReLU activation and dropout for regularization.
- Model Compilation: The model is compiled using the Stochastic Gradient Descent (SGD) optimizer and categorical cross-entropy loss function.
- Model Training: The model is trained on the preprocessed data for a specified number of epochs.
- Model Loading: The pre-trained chatbot model is loaded from the
chatbotmodel.h5
file. - Data Loading: The words and classes used during training are loaded from the pickle files.
- Input Processing: User input is cleaned, tokenized, and converted into a bag-of-words representation.
- Intent Prediction: The model predicts the intent of the user input based on the bag-of-words representation.
- Response Generation: Based on the predicted intent, a response is selected randomly from the predefined responses associated with that intent.
- User Interaction: The chatbot continuously interacts with the user, predicting intents and generating responses based on user input.
- Python
- Libraries: NLTK, TensorFlow, Keras, NumPy
- File Serialization: Pickle (for storing words and classes)
- Install the required Python libraries (NLTK, TensorFlow, Keras).
- Download the training data (
intent.json
) and place it in the project directory. - Run
training.py
to train the chatbot model and generate necessary pickle files and the trained model file. - Run
chatbot.py
to start the chatbot interaction. Enter messages in the console to chat with the bot.
For any improvements or feedback, please feel free to contribute or reach out.