Skip to content

hammadansari16/Chatbot-with-Python-and-Machine-Learning-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chatbot-with-Python-and-Machine-Learning-

This repository contains a Python implementation of a simple retrieval-based chatbot. The chatbot is designed to understand user intents and provide appropriate responses by leveraging Natural Language Processing (NLP) techniques and a deep learning model built with TensorFlow/Keras.

📋 Project Overview The goal of this project is to create a conversational agent capable of classifying user inputs into predefined categories (intents) and selecting a suitable response. The system uses a JSON file to define intents, patterns (user queries), and responses. It processes text data, trains a neural network on the patterns, and then uses the trained model to predict the intent of new user messages.

🛠️ Technologies Used Python: Core programming language.

NLTK (Natural Language Toolkit): For text preprocessing (tokenization, lemmatization).

TensorFlow / Keras: For building and training the neural network model.

NumPy: For numerical operations and data handling.

Pickle: For serializing and saving the preprocessed data (words and classes).

JSON: For structuring the intents dataset.

📂 Dataset Structure The chatbot relies on an intents.json file. This file contains the training data in the following structure:

Tag: A unique label for the intent (e.g., "greeting", "goodbye", "options").

Patterns: A list of example sentences a user might type (e.g., "Hi", "How are you", "What can you do?").

Responses: A list of possible answers the bot can give for that intent.

Example:

JSON

{ "intents": [ { "tag": "greeting", "patterns": ["Hi", "Hello", "Is anyone there?"], "responses": ["Hello!", "Good to see you again!", "Hi there, how can I help?"] } ] } 🚀 Methodology Data Loading: The intents.json file is loaded and parsed.

Preprocessing:

Tokenization: Breaking down sentences into individual words.

Lemmatization: Reducing words to their base or root form (e.g., "running" -> "run") using WordNetLemmatizer.

Bag of Words (BoW): Converting sentences into numerical arrays (binary vectors) representing the presence of known vocabulary words.

Model Architecture:

A Sequential neural network is built using Keras.

Input Layer: Matches the size of the vocabulary (bag of words length).

Hidden Layers: Dense layers with ReLU activation and Dropout for regularization to prevent overfitting.

Output Layer: A Dense layer with Softmax activation to output probabilities for each intent class.

Optimizer: SGD (Stochastic Gradient Descent) with Nesterov momentum.

Training: The model is trained on the prepared training data (patterns as input, intent tags as output).

Prediction & Response:

The user's input is preprocessed and converted to a bag of words.

The model predicts the intent with the highest probability.

A random response associated with that intent is returned.

📊 Model Details Type: Deep Neural Network (DNN)

Loss Function: Categorical Crossentropy

Metrics: Accuracy

Training: Typically runs for 200 epochs with a batch size of 5.

⚠️ Limitations & Future Improvements Context Handling: This simple bot does not maintain conversation context or memory of previous messages.

Dataset Size: The accuracy is highly dependent on the variety and quantity of patterns in intents.json.

Future Work:

Implement context handling for multi-turn conversations.

Integrate with a messaging platform (e.g., Telegram, Discord).

Use more advanced embeddings like Word2Vec or BERT instead of Bag of Words.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors