Skip to content

phching/simpleAIChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Intent-Based AI Chatbot

A lightweight, neural network-powered chatbot that recognizes user intents using a bag-of-words approach + a small feed-forward neural network built with PyTorch.

Currently recognizes the following intents:

  • greeting
  • goodbye
  • programming (explains what coding is)
  • resource (recommends learning resources)
  • stocks (shows a random selection from your "portfolio")

Features

  • Intent classification using a 3-layer feed-forward neural network
  • Bag-of-words (binary) input representation
  • Tokenization + lemmatization with NLTK
  • PyTorch model training & inference
  • Supports function calling (e.g. stocks intent → calls get_stocks())
  • Model saving & loading
  • Simple command-line chat interface

Demo

Enter your message: hi
Hello!

Enter your message: how can i learn coding?
Check out the NeuralNine YouTube channel and The Python Bible series (7 in 1).

Enter your message: what are my stocks?
Here are your stocks!
['NVDA', 'META', 'MSFT']

Enter your message: bye
Goodbye!

Project Structure

chatbot/
├── main.py              # Main application + model + training loop
├── intents.json         # Training patterns + responses
├── chatbot_model.pth    # Trained model weights (after training)
├── dimensions.json      # Input/output size info for loading
└── README.md

Requirements

Python 3.8+
torch
numpy
nltk

Install dependencies:

uv add install torch numpy nltk

Then download required NLTK data (only needed once):

import nltk
nltk.download('punkt')
nltk.download('wordnet')
nltk.download('omw-1.4')   # optional but recommended

How to Use

Option 1: Use the pre-trained model

uv run main.py

Option 2: Retrain the model from scratch

Uncomment these lines in main.py

assistant = ChatbotAssistant('intents.json', function_mappings = {'stocks': get_stocks})
assistant.parse_intents()
assistant.prepare_data()
assistant.train_model(batch_size=8, learning_rate=0.001, epochs=100)
assistant.save_model('chatbot_model.pth', 'dimensions.json')

Then run:

uv run main.py

The model will be retrained and saved.

How to Add New Intents

  1. Open intents.json
  2. Add a new intent object like this:
    {
    "tag": "thanks",
    "patterns": ["Thanks", "Thank you", "Thx", "Appreciate it"],
    "responses": ["You're welcome!", "Anytime!", "Glad I could help"]
    }
  3. (Optional) Add a function mapping in main.py:
    function_mappings = {
        'stocks': get_stocks,
        'thanks': lambda: print("Extra action: sending virtual high-five!")
    }
  4. Retrain the model (see Option 2 above)

Current Limitations & Possible Improvements

  • Very small dataset → performance is limited on unseen phrases
  • Binary bag-of-words → no word order or frequency information
  • No handling of out-of-scope questions (falls back to predicted intent)
  • No context/memory between messages

Future ideas

  • Use TF-IDF instead of binary BoW
  • Add word embeddings (e.g. pretrained GloVe / fastText)
  • Implement a larger model (LSTM / Transformer)
  • Add entity extraction (names, dates, products…)
  • Connect to real APIs (weather, news, real stock data…)
  • Create a web / Discord / Telegram interface

License

  • MIT License – feel free to use, modify, and share.

About

A simple cli-based porject of AI chatbot

Resources

Stars

Watchers

Forks

Contributors

Languages