This is a learning project designed to understand the basics of machine learning and natural language processing using Python. It implements a simple chatbot that can be trained to recognise intents and carry out basic conversations.
The project consists of two main components:
- Training Module (
train.py)
- Processes training data from
intents.json - Uses a neural network to learn patterns
- Creates a model that can recognise user intents
- Implements Bag of Words (BoW) approach for text processing
- Chatbot Module (
chatbot.py)
- Uses the trained model to understand user input
- Manages conversation flow
- Extracts entities (like amounts, names)
- Provides contextual responses
The chatbot can handle:
- Basic conversations
- Money transfers
- Balance enquiries
- Loan enquiries
- Multi-step conversations
- Context maintenance
- Python 3.8+
- TensorFlow (macOS optimized)
- NLTK (Natural Language Toolkit)
- NumPy
- Create and Activate Conda Environment
# Create new environment
conda create -n tensorflow python=3.8
# Activate environment
conda activate tensorflow- Install TensorFlow Dependencies
# Install base dependencies
conda install tensorflow-deps
# Install macOS optimized TensorFlow
pip install tensorflow-macos
# Install Metal acceleration (Apple Silicon)
pip install tensorflow-metal- Install Required Packages
# Install NLTK
pip install nltk
# Install NumPy
pip install numpy- Prepare Training Data
- Review intents.json
- Add/modify intents as needed
- Format:
jsonCopy{ "intents": [ { "tag": "greeting", "patterns": ["hi", "hello"], "responses": ["Hello!", "Hi there!"] } ] }
- Run Training
python train.pyThis will:
- Process the intents
- Train the neural network
- Save the model as 'chatbot_model.h5'
- Save vocabulary as 'words.pkl'
- Save classes as 'classes.pkl'
- Start the Chatbot
python chatbot.py- Interact with the Bot
- Type your messages
- Bot will respond based on trained intents
- Type "quit" to exit