Skip to content

ZarhanMemon/pytorch-intent-chatbot

Repository files navigation

🧠 AI – Intent Based Chatbot (PyTorch + Tkinter)

A simple desktop chatbot built using Natural Language Processing (NLP) and PyTorch.
This chatbot understands user input, predicts the intent using a neural network, and responds accordingly through a clean Tkinter GUI.


📌 Project Overview

This project is an intent classification chatbot.

It works by:

  1. Converting user text into numerical format (Bag of Words)
  2. Passing it through a Neural Network
  3. Predicting the most likely intent
  4. Returning a predefined response

The goal of this project was to understand:

  • How chatbots process text
  • How machine learning models classify text
  • How neural networks work in real applications
  • How to connect ML models with a GUI

🛠 Technologies Used

  • Python 3
  • PyTorch (Neural Network)
  • NLTK (Tokenization & Stemming)
  • Tkinter (GUI)
  • NumPy

🧠 How It Works (Simple Explanation)

1️⃣ Text Preprocessing

  • Tokenization (splitting sentence into words)
  • Lowercasing
  • Stemming (reducing words to root form)
  • Removing punctuation

2️⃣ Bag of Words

Each sentence is converted into a numerical vector.

Example:

Input:

"Hello how are you?"

Converted into:

[0, 1, 0, 1, 0, ...]

This allows the neural network to understand text mathematically.


3️⃣ Neural Network Architecture

  • Input Layer → Bag of Words size
  • Hidden Layer 1 → ReLU
  • Hidden Layer 2 → ReLU
  • Output Layer → Number of intents

Loss Function: CrossEntropyLoss
Optimizer: Adam

The output layer gives probability scores for each intent.


4️⃣ Intent Prediction

The model:

  • Predicts the highest probability intent
  • If confidence > 75%, it returns a response
  • Otherwise, it says it doesn’t understand

🖥 GUI Interface

The chatbot runs inside a simple Tkinter desktop window.

Features:

  • Clean student-level UI
  • User & Bot message colors
  • Send button + Enter key support
  • Scrollable chat window

🚀 How To Run

1️⃣ Install dependencies

pip install torch nltk numpy

2️⃣ Train the model

python train.py

3️⃣ Run the GUI

python gui.py

📂 Project Structure

SMART-AI-Chatbot/
│
├── train.py
├── gui.py
├── model.py
├── nltk_utils.py
├── intents.json
├── data.pth
└── README.md

WORKING Screenshot

Screenshot 1 Screenshot 2

Screenshot 3 Screenshot 4

Screenshot 5


🎯 What I Learned From This Project

  • How text is converted into numbers
  • How neural networks classify text
  • Understanding of input size, hidden layers, and output layers
  • Using PyTorch for training models
  • Connecting ML models with a GUI
  • Debugging real ML errors

📌 Future Improvements

  • Add more intents
  • Use advanced NLP models (like Transformers)
  • Add memory/context support
  • Improve GUI design
  • Deploy as web application

📖 Learning Note

This project was built as a learning exercise by referencing tutorials and understanding each component step-by-step.
The goal was not just to copy, but to understand how chatbot systems work internally.


👨‍💻 Author

Built as part of my Machine Learning & NLP learning journey.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages