Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Lesson 11 of 12
Module 2 Practice
Apply the concepts from this module with a hands-on practice exercise.
Practice: Explore Model Limits
Practice: Explore Model Limits
# Practice exercise: explore how context and token limits affect AI responses
# This code simulates how a context window works
# In a real AI system, the context is managed automatically
def simulate_context_window(max_tokens=10):
"""Simulate a simple context window."""
conversation = []
total_tokens = 0
print(f"Context window simulation (max {max_tokens} tokens)")
print("=" * 50)
messages = [
"Hello, my name is Alice.",
"I am learning about Generative AI.",
"I find prompt engineering fascinating.",
"What is the capital of France?",
"Thank you for the helpful answer.",
]
for msg in messages:
tokens_in_message = len(msg.split()) # simplified token count
if total_tokens + tokens_in_message > max_tokens:
# Remove oldest message to make room (simplified)
if conversation:
removed = conversation.pop(0)
removed_tokens = len(removed.split())
total_tokens -= removed_tokens
print(f" [Context full - removed: '{removed}']")
conversation.append(msg)
total_tokens += tokens_in_message
print(f"Added: '{msg}' ({tokens_in_message} tokens)")
print(f"Current context ({total_tokens} tokens): {conversation}")
print()
simulate_context_window(max_tokens=15)Diagram
Loading diagram…
Practice Diagram
Try It Yourself
Try It YourselfHTML
HTML Editor
✓ ValidTab = 2 spaces
HTML|32 lines|1170 chars|✓ Valid syntax
UTF-8
Key Takeaways from Module 2
- Generative AI works in two phases: training (learning) and inference (generating for users)
- Training data is the raw material the AI learns from - its quality directly affects the model's quality
- An AI model is a mathematical structure with billions of parameters storing learned patterns
- Tokens are the small chunks of text that AI models process - roughly 100 tokens equals 75 English words
- The context window is the maximum amount of text the model can process at once
- Training changes the model's parameters. Inference applies fixed parameters to a new input
- Most AI chat tools do not learn from your conversations - their parameters are fixed after training
Key Takeaways
- Apply the concepts from this module with a hands-on practice exercise.
- Generative AI works in two phases: training (learning) and inference (generating for users)
- Training data is the raw material the AI learns from - its quality directly affects the model's quality
- An AI model is a mathematical structure with billions of parameters storing learned patterns
Finished this lesson?
0 of 12 in Module 2