A High-Performance Deep Learning Conversational AI Assistant Powered by PyTorch & NLP
- π Project Overview
- π§ Deep Learning & NLP Course Curriculum
- π¬ Natural Language Processing (NLP) Pipeline
- ποΈ PyTorch Deep Neural Network Architecture
- β¨ Key Advancements & Features
- π Repository File Tree
- π Quick Start Installation
- π― Training the Model
- π¬ Running the Chatbot (CLI & Desktop GUI)
- βοΈ Customizing & Adding New Domains
- π€ Author & License
Chatbot_with_Pytorch is an enterprise-ready, educational, and high-performance conversational AI system developed and architected by Rahul Chaube.
Unlike naive rule-based keyword matchers, this chatbot utilizes a Deep Multi-Layer Perceptron (MLP) implemented in PyTorch to perform statistical intent classification on tokenized and stemmed text vectors generated via NLTK.
The repository includes:
- Academic Deep Learning Course (
LESSONS.md): Full mathematical derivations, backpropagation formulas, activation proofs, and optimization theory. - Interactive Terminal CLI (
chat.py): ANSI-colored console interface with slash commands (/help,/tags,/info,/verbose). - Desktop Graphical Application (
app.py): Modern, dark-themed GUI built with Tkinter. - Configurable Training Pipeline (
train.py): Hyperparameter CLI flags (--epochs,--lr,--batch-size,--hidden-size,--dropout,--seed).
Explore the full in-depth textbook and course guide in LESSONS.md:
| Module | Topic | Core Concepts Covered |
|---|---|---|
| Module 1 | NLP Foundations | Word Tokenization, Porter Stemmer algorithm, Bag-of-Words (BoW) vector representation |
| Module 2 | Neural Network Architecture | Multi-Layer Perceptrons, Linear transforms, ReLU activations, Dropout regularization, Softmax |
| Module 3 | Training & Optimization | Cross-Entropy Loss mathematical formulation, Adam optimizer moment estimation, mini-batch gradient descent |
| Module 4 | Inference & Production | Dynamic confidence thresholding, Out-of-Distribution (OOD) fallbacks, Tkinter GUI engineering |
| Module 5 | Practical Labs | Hands-on exercises to build custom enterprise chatbots |
The transformation from raw human dialogue to mathematical input tensors proceeds through 4 well-defined phases:
-
Text Tokenization: Splits input strings into discrete linguistic tokens using
nltk.word_tokenize. - Porter Stemming: Normalizes inflected word variants ("running", "runs", "ran") into their root lemma ("run").
-
Vocabulary Indexing & Bag-of-Words Vectorization: Matches stems against the sorted unique corpus vocabulary
$V \in \mathbb{R}^{124}$ , producing a binary${0, 1}$ feature vector. -
Tensor Conversion: Casts vectors into PyTorch
torch.float32tensors ready for matrix multiplication on CPU or CUDA GPU.
The core classification engine is a 3-layer Feed-Forward Multi-Layer Perceptron (NeuralNet in model.py):
-
Input Dimension (
$d_{\text{in}}$ ):$124$ features (Bag-of-Words vocabulary size). -
Hidden Dimensions (
$h_1, h_2$ ):$16$ units with non-linear ReLU activations and optional Dropout ($p = 0.05$ ). -
Output Classes (
$C$ ):$13$ intent classes with Softmax probability distribution.
- β‘ Near-Zero Convergence: Optimized training loop achieving final loss
$\le 0.000002$ . - π‘οΈ Confidence Threshold Gating: Out-of-domain and low-confidence inputs are intercepted to prevent hallucinated answers.
- π¨ Modern Minimalist Visuals: High-resolution, clean vector architecture diagrams.
- π₯οΈ Cross-Platform Compatibility: Fully tested on Windows (PowerShell/CMD), macOS, and Linux.
Chatbot_with_Pytorch/
βββ assets/
β βββ banner.png # Clean minimalist project hero banner
β βββ nlp_pipeline.png # Infographic: Tokenization to BoW tensor
β βββ neural_network_architecture.png# Infographic: PyTorch MLP forward pass
βββ intents.json # Knowledge base with 13 intent categories
βββ model.py # PyTorch NeuralNet architecture class
βββ nltk_utils.py # Tokenization, Stemming & BoW vectorizer
βββ train.py # CLI-configurable PyTorch training pipeline
βββ chat.py # Interactive ANSI terminal CLI assistant
βββ app.py # Modern Tkinter desktop GUI application
βββ LESSONS.md # Complete deep learning & NLP coursebook
βββ data.pth # Serialized model checkpoint & vocabulary
βββ LICENSE # MIT License (Rahul Chaube)
βββ README.md # Main repository documentation
git clone https://github.com/Rahulchaube1/Chatbot_with_Pytorch.git
cd Chatbot_with_Pytorchuv venv .venv
.\.venv\Scripts\activate
uv pip install torch nltk numpypython -m venv .venv
.\.venv\Scripts\activate
pip install torch nltk numpypython -c "import nltk; nltk.download('punkt'); nltk.download('punkt_tab')"Execute the training script to train the neural network on intents.json:
python train.pypython train.py --epochs 1000 --batch-size 8 --lr 0.001 --hidden-size 16 --dropout 0.05| Flag | Type | Default | Description |
|---|---|---|---|
--intents |
str |
intents.json |
Path to JSON intent dataset |
--output |
str |
data.pth |
Target output model checkpoint file |
--epochs |
int |
1000 |
Total training epochs |
--batch-size |
int |
8 |
Mini-batch sample size |
--lr |
float |
0.001 |
Learning rate for Adam optimizer |
--hidden-size |
int |
16 |
Number of neurons per hidden layer |
--dropout |
float |
0.05 |
Dropout regularization probability |
--seed |
int |
42 |
Random seed for deterministic reproducibility |
python chat.py --verbose/helpβ Display command list/tagsβ View all 13 recognizable intent tags/infoβ View active PyTorch model architecture and parameters/verboseβ Toggle live intent and confidence percentagesquit/exitβ Close chat session
python app.pyLaunches a standalone desktop application window featuring auto-scrolling dialogue, color-coded speech bubbles, and instant response generation.
To train the chatbot for customer support, medical inquiries, e-commerce, or personal portfolios:
- Open
intents.json. - Append a new intent block:
{
"tag": "contact_info",
"patterns": [
"How can I reach Rahul Chaube?",
"Where can I contact the developer?",
"Show me contact details"
],
"responses": [
"You can connect with Rahul Chaube via GitHub at https://github.com/Rahulchaube1!"
]
}- Run
python train.py. - Your bot is immediately upgraded with the new capabilities!
- Architect & Lead Developer: Rahul Chaube
- Repository: https://github.com/Rahulchaube1/Chatbot_with_Pytorch
- License: Licensed under the MIT License.


