This project demonstrates how to build a generative AI chatbot using GPT-2. It includes educational comments to help you understand what's happening.
-
Install dependencies:
pip install -r requirements.txt
-
Run the Gradio web interface (Recommended):
# Option A: Use the launcher script (easiest) ./start_kylebot.sh # Option B: Manual start source kylebot_env/bin/activate python kylebot_gradio.py
Then open your browser to:
http://localhost:7860 -
Or run the command-line version:
python kylebot_fixed.py
-
Or use the Jupyter notebook:
jupyter notebook kylebot.ipynb
- Model Loading & Setup: How to load pre-trained language models
- Text Generation Strategies:
- Greedy Decoding (always picks most likely word)
- Sampling (creative, uses temperature and top-k)
- Beam Search (explores multiple possibilities)
- Conversational Interface: Building an interactive chat loop
- Parameter Tuning: Understanding how different parameters affect responses
- Modern UI: Beautiful, responsive web interface
- Real-time chat: Type messages and get instant responses
- Parameter controls: Adjust temperature, top-k, and max tokens with sliders
- Method switching: Easily switch between generation methods
- Clear chat: Start fresh conversations with one click
- Mobile friendly: Works on phones and tablets
quit- Exit the chatmethod: [greedy/sampling/beam]- Change generation methodhistory- See conversation historyhelp- Show this help messagetest- Run generation method tests
-
Greedy Decoding (
method: greedy)- Always picks the most likely next word
- Fast and predictable
- Good for simple, factual responses
-
Sampling (
method: sampling)- Uses temperature and top-k parameters
- More creative and diverse responses
- Temperature: 0.1 (focused) to 1.5 (creative)
- Top-k: Limits word choices to top k most likely
-
Beam Search (
method: beam)- Explores multiple possible sequences
- Balanced quality and coherence
- Uses num_beams parameter (more beams = potentially better quality)
- Temperature: Controls randomness (0.1 = focused, 1.5 = creative)
- Top-k: Limits word choices to top k most likely
- Max Length: Controls response length
- Num Beams: Number of parallel searches in beam search
- No Repeat N-gram Size: Prevents repetition of phrases
- Repetition Penalty: Reduces repetitive text
- Modern Design: Clean, professional interface with Soft theme
- Real-time Chat: Instant responses with typing indicators
- Parameter Controls: Interactive sliders for temperature, top-k, and max tokens
- Method Selection: Dropdown to switch between generation methods
- Chat History: Persistent conversation memory
- Mobile Responsive: Works great on all devices
- Network Access: Can be accessed from other devices on your network
- Interactive Chat: Terminal-based conversation
- Method Testing: Built-in tests for all generation methods
- History Management: View and clear conversation history
- Parameter Experimentation: Easy parameter adjustment
The original notebook had a parameter passing issue where the generate_response_greedy function didn't accept **kwargs. The fixed versions resolve this by:
- Adding
**kwargsto all generation functions - Properly passing parameters through to the model.generate() calls
- Removing debug print statements for cleaner output
- Creating a beautiful web interface with Gradio
- Start with sampling (temperature 0.7-0.9) for most use cases
- Use beam search for factual or technical responses
- Greedy decoding is good for simple, predictable tasks
- Always clean and format your responses
- Keep conversation history for context
- Fine-tuning: Train the model on your own data
- Different Models: Try GPT-3, BERT, or other models
- Web Interface: Build a web app for your chatbot
- Memory: Add long-term conversation memory
- Personality: Customize the bot's responses
- Multi-turn: Handle complex conversations
Happy learning! 🎉
llm/
├── kylebot_learning.ipynb # Main learning notebook
├── requirements.txt # Python dependencies
├── README.md # This file
└── .gitignore # Git ignore file
-
Greedy Decoding
- Always picks the most likely next word
- Fast but can be repetitive
- Good for simple, predictable tasks
-
Sampling
- Randomly selects from likely words
- More creative and diverse
- Controlled by temperature and top-k parameters
-
Beam Search
- Explores multiple possible sequences
- Balanced quality and coherence
- Slower but often better results
- Temperature: Controls randomness (0.1 = focused, 1.5 = creative)
- Top-k: Limits word choices to top k most likely
- Max Length: Controls response length
- Num Beams: Number of parallel searches in beam search
- Start Simple: Use the basic chat interface
- Experiment: Try different parameters and methods
- Understand: Read the educational comments
- Customize: Modify the code to add features
- Build: Create your own chatbot variations
This is a learning project! Feel free to:
- Add new features
- Improve the documentation
- Share your experiments
- Ask questions
Happy learning! 🎉
Note: This project uses GPT-2, which is a powerful but older model. For production use, consider newer models like GPT-3, GPT-4, or open-source alternatives.