Academic AI Project | Computer Engineering | CHARUSAT
Course: Natural Language Processing / AI (2022)
Student: Sahil Patel (20CE101)
Approach: Intent Matching + Deep Learning
Model: Neural Network (TensorFlow/Keras)
An intent-based conversational AI chatbot built from scratch using Natural Language Processing (NLP) and Deep Learning. The bot understands user queries through pattern matching and responds intelligently using a trained neural network.
Key Features:
- β Intent Classification - Understands user intent from messages
- β NLP Processing - Tokenization, lemmatization, bag-of-words
- β Deep Learning - Custom neural network (128-64 neurons)
- β JSON-based Training - Easy-to-extend intent patterns
- β Real-time Responses - Interactive command-line chat
- β Pre-trained Model - Ready to use chatbotmodel.h5
User Input β Tokenization β Lemmatization β Bag of Words β Neural Network β Intent Prediction β Response Selection
- Load intents from JSON
- Tokenize patterns using NLTK
- Lemmatize words (WordNetLemmatizer)
- Create bag-of-words representation
- Build neural network (Sequential model)
- Train on patterns-intent pairs
- Save model as chatbotmodel.h5
- Load trained model
- Accept user input
- Process through NLP pipeline
- Predict intent with confidence threshold
- Select random response from matching intent
- Display to user
Chatbot-from-Scratch/
βββ chatbot.py # Main chatbot runtime (83 lines)
βββ training.py # Model training script (81 lines)
βββ intents.json # Intent patterns and responses (120 lines)
βββ chatbotmodel.h5 # Trained model (174 KB)
βββ words.pkl # Vocabulary pickle file
βββ classes.pkl # Intent classes pickle file
βββ requirements.txt # Python dependencies
βββ .gitignore # Git ignore patterns
βββ LICENSE # MIT License
βββ README.md # This file
Python 3.7+
TensorFlow 2.x
NLTK# Clone repository
git clone https://github.com/patelsahil2k03/Chatbot-from-Scratch.git
cd Chatbot-from-Scratch
# Install dependencies
pip install -r requirements.txt
# Download NLTK data
python -c "import nltk; nltk.download('punkt'); nltk.download('wordnet'); nltk.download('omw-1.4')"# Run chatbot with existing model
python chatbot.py# Train new model
python training.py
# Run chatbot
python chatbot.py$ python chatbot.py
GO! BOT IS RUNNING !
> Hello
Hi there, how can I help?
> What do you sell?
We sell coffee and tea
> Tell me a joke
Why did the hipster burn his mouth? He drank the coffee before it was cool.
> Thanks
Happy to help!
> Bye
See you later, thanks for visitingmodel = Sequential()
model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(len(train_y[0]), activation='softmax'))Layers:
- Input Layer: Variable size (vocabulary length)
- Hidden Layer 1: 128 neurons + ReLU + 50% Dropout
- Hidden Layer 2: 64 neurons + ReLU + 50% Dropout
- Output Layer: Softmax (number of intent classes)
Training Configuration:
- Optimizer: SGD (Stochastic Gradient Descent)
- Learning Rate: 0.01
- Momentum: 0.9 (Nesterov)
- Loss: Categorical Cross-entropy
- Epochs: 200
- Batch Size: 5
- greeting - Hi, Hello, Hey
- goodbye - Bye, See you later
- thanks - Thank you, Thanks a lot
- items - What do you sell?
- payments - Payment methods
- delivery - Shipping information
- funny - Tell me a joke
- time period - Internship duration (custom)
- hours - Business hours
- name - Bot name (Flash)
{
"tag": "your_intent",
"patterns": [
"User question 1",
"User question 2",
"User question 3"
],
"responses": [
"Bot response 1",
"Bot response 2"
]
}After adding, retrain the model:
python training.py- TensorFlow/Keras - Deep learning framework
- NLTK - Natural language processing
- NumPy - Numerical computations
- Pickle - Model serialization
- JSON - Intent data storage
- Tokenization - Split text into words
- Lemmatization - Reduce words to base form
- Bag of Words - Convert text to numerical vectors
- Intent Classification - Categorize user messages
- Sequential Neural Network - Feedforward architecture
- Dense Layers - Fully connected neurons
- Dropout - Regularization to prevent overfitting
- Softmax Activation - Multi-class probability distribution
Key Functions:
- Load intents from JSON
- Tokenize and lemmatize patterns
- Create vocabulary (words) and classes (intents)
- Generate bag-of-words training data
- Build and compile neural network
- Train model (200 epochs)
- Save model and pickles
Output Files:
chatbotmodel.h5- Trained modelwords.pkl- Vocabulary listclasses.pkl- Intent classes
Key Functions:
clean_up_sentence(sentence)
# Tokenizes and lemmatizes input
bag_of_words(sentence)
# Converts sentence to numerical vector
predict_class(sentence)
# Predicts intent with confidence threshold (0.25)
get_response(intents_list, intents_json)
# Selects random response from matched intentWorkflow:
- Load model and pickles
- Enter infinite chat loop
- Process user input through NLP pipeline
- Predict intent (with 25% confidence threshold)
- Select and display response
Course: Natural Language Processing / Artificial Intelligence
Semester: 4th/5th Semester (2022)
Institution: CHARUSAT - CSPIT
Program: B.Tech Computer Engineering
Student ID: 20CE101
Purpose: Build conversational AI from scratch to understand NLP and neural networks.
This repository represents foundational NLP/AI learning from 2022.
Journey Since Then:
- π€ Built production chatbots with LangChain and advanced LLMs
- π Achieved 98%+ accuracy in AI models (production systems)
- π¬ Published 2 SCOPUS-indexed papers on AI/ML
- π Top 10 Finalist in AI-Manthan Hackathon
- βοΈ Deployed 50+ AWS Lambda AI functions
- πΌ Associate Software Engineer building AI solutions at Digiflux
Current Expertise: LangChain, GPT, BERT, Transformers, Production NLP
Portfolio: patelsahil2k03.github.io
- β Tokenization - Text preprocessing fundamentals
- β Lemmatization - Word normalization techniques
- β Bag of Words - Text vectorization
- β Intent Recognition - Classification problems
- β Neural Networks - Architecture design
- β Backpropagation - Training process
- β Dropout - Regularization techniques
- β Softmax - Multi-class classification
- β Modular Design - Separate training and inference
- β Model Persistence - Saving/loading models
- β JSON Configuration - Data-driven approach
- β Error Handling - Confidence thresholds
Edit intents.json responses to match desired tone.
Add new intent blocks for your use case (e-commerce, support, etc.)
- Increase epochs (200 β 500)
- Add more training patterns per intent
- Tune hyperparameters (learning rate, neurons)
- Use language-specific lemmatizers
- Translate intents.json
Wrap chatbot.py logic in Flask/Streamlit for web interface
- Training Time: ~2-5 minutes (200 epochs)
- Model Size: 174 KB (lightweight)
- Response Time: < 100ms per query
- Confidence Threshold: 25% (adjustable)
- Intent Accuracy: Depends on training data quality
This is an academic learning project. Feedback welcome!
Enhancement Ideas:
- Add more intents (100+ for robust bot)
- Implement context handling (conversation memory)
- Add sentiment analysis
- Integrate with web/mobile interface
- Add voice input/output
MIT License - See LICENSE file for details.
Sahil Patel
Email: patelsahil2k03@gmail.com
Portfolio: patelsahil2k03.github.io
GitHub: @patelsahil2k03
LinkedIn: sahil-patel-581226205
- CHARUSAT CSPIT - NLP/AI curriculum
- TensorFlow Team - Excellent deep learning library
- NLTK - Comprehensive NLP toolkit
- AI Community - Inspiration and resources
- NLTK Documentation: https://www.nltk.org/
- TensorFlow Keras: https://www.tensorflow.org/guide/keras
- Intent-based Chatbot tutorials
- Bag-of-Words model explanations
From basic intent matching to building production LLM applications - this project marks the beginning of my AI journey.
Last Updated: March 2026