Chapter 3: Overview of AI Language Models
π― Learning Objectivesβ
After completing this chapter, you will be able to:
- Explain how large language models (LLMs) work at a high level
- Compare major AI models and their unique strengths
- Identify which model is best suited for different tasks
- Understand key limitations of current AI models
π Introductionβ
To become an effective prompt engineer, you need to understand the tools you're working with. In this chapter, we'll explore how AI language models work and compare the major players in the field.
How LLMs Work (Simplified)β
Large Language Models are AI systems trained on vast amounts of text to understand and generate human-like language.
The Basic Conceptβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HOW LLMs WORK β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β INPUT (Your Prompt) β
β β β
β βΌ β
β βββββββββββββββ β
β β TOKENIZATION β β Break text into tokens β
β ββββββββ¬βββββββ β
β β β
β βΌ β
β βββββββββββββββ β
β β EMBEDDING β β Convert tokens to numbers β
β ββββββββ¬βββββββ β
β β β
β βΌ β
β βββββββββββββββ β
β β TRANSFORMER β β Process through neural network β
β ββββββββ¬βββββββ β
β β β
β βΌ β
β βββββββββββββββ β
β β PREDICTION β β Predict most likely next token β
β ββββββββ¬βββββββ β
β β β
β βΌ β
β OUTPUT (AI Response) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key Conceptsβ
| Concept | Explanation | Why It Matters |
|---|---|---|
| Token | Basic unit of text (roughly 4 characters) | Affects pricing and context limits |
| Context Window | Maximum input + output length | Determines how much info AI can consider |
| Parameters | Model's learned weights (billions) | More parameters often = more capable |
| Temperature | Randomness in output | Higher = more creative, Lower = more consistent |
| Training Data | Text the model learned from | Affects knowledge and biases |
Understanding Tokensβ
"Hello, how are you?"
Tokenized: ["Hello", ",", " how", " are", " you", "?"]
= 6 tokens
Token count varies by model:
β’ GPT: ~4 characters per token
β’ Claude: Similar to GPT
β’ Some models use different tokenization
Understanding tokens helps you:
- Estimate costs
- Stay within context limits
- Write more efficient prompts
Major AI Models Comparedβ
Let's explore the major players in the LLM space:
OpenAI Models (GPT Family)β
GPT-4 / GPT-4 Turboβ
| Feature | Details |
|---|---|
| Company | OpenAI |
| Context Window | 8K-128K tokens |
| Strengths | Reasoning, coding, general knowledge |
| Best For | Complex tasks, analysis, creative writing |
| Access | ChatGPT Plus, API |
Example Prompt Style:
You are an expert Python developer. Review this code
and provide specific improvements with explanations:
[code here]
GPT-3.5 Turboβ
| Feature | Details |
|---|---|
| Context Window | 4K-16K tokens |
| Strengths | Speed, cost-efficiency |
| Best For | Simple tasks, high-volume applications |
| Cost | ~20x cheaper than GPT-4 |
Anthropic Models (Claude Family)β
Claude 3 (Opus, Sonnet, Haiku)β
| Variant | Strength | Use Case |
|---|---|---|
| Opus | Most capable | Complex analysis, research |
| Sonnet | Balanced | General purpose, coding |
| Haiku | Fastest, cheapest | Quick tasks, high volume |
Claude's Unique Features:
- Constitutional AI (built-in safety)
- Excellent at following complex instructions
- Strong performance with XML-structured prompts
- Very long context window (200K tokens)
Example Prompt Style:
<context>
You are a helpful assistant analyzing customer feedback.
</context>
<task>
Categorize the following review and extract key themes:
</task>
<review>
[customer review text]
</review>
<output_format>
- Category: [positive/negative/neutral]
- Key themes: [bulleted list]
- Summary: [one sentence]
</output_format>
Meta Models (Llama Family)β
Llama 2 & Llama 3β
| Feature | Details |
|---|---|
| Company | Meta |
| License | Open source (mostly) |
| Sizes | 7B, 13B, 70B parameters |
| Strengths | Customizable, self-hostable, free |
| Limitations | Less capable than GPT-4/Claude 3 |
Best For:
- Organizations needing data privacy
- Custom fine-tuning
- Cost-sensitive applications
- Research and experimentation
Other Notable Modelsβ
| Model | Company | Notable Feature |
|---|---|---|
| Gemini | Multimodal, integrated with Google services | |
| Mistral | Mistral AI | High quality open-source alternative |
| Command | Cohere | Enterprise-focused, RAG optimized |
| Grok | xAI | Real-time information access |
Model Comparison Matrixβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MODEL COMPARISON β
βββββββββββββββ¬ββββββββββββ¬βββββββββββ¬ββββββββββ¬βββββββββββββββ€
β β GPT-4 β Claude 3 β Llama 3 β Gemini Pro β
βββββββββββββββΌββββββββββββΌβββββββββββΌββββββββββΌβββββββββββββββ€
β Reasoning β β
β
β
β
β
β β
β
β
β
β
β β
β
β
β
β β
β
β
β
β
β
β Coding β β
β
β
β
β
β β
β
β
β
β
β β
β
β
β
β β
β
β
β
β
β Creative β β
β
β
β
β
β β
β
β
β
β β
β
β
β β
β
β
β
β
β Context β β
β
β
β
β β
β
β
β
β
β β
β
β
β β
β
β
β
β
β Speed β β
β
β
β β
β
β
β
β β
β
β
β
β
β β
β
β
β
β
β Cost β β
β
β β
β
β
β β
β
β
β
β
β β
β
β
β
β Privacy β β
β
β
β β
β
β
β β
β
β
β
β
β β
β
β
β
βββββββββββββββ΄ββββββββββββ΄βββββββββββ΄ββββββββββ΄βββββββββββββββ
Understanding Limitationsβ
All AI models have limitations that affect how you should prompt them:
1. Knowledge Cutoffβ
Models are trained on data up to a certain date:
| Model | Approximate Cutoff |
|---|---|
| GPT-4 | April 2023 (varies) |
| Claude 3 | Early 2024 |
| Llama 3 | December 2023 |
Always verify time-sensitive information. The model doesn't know recent events.
2. Hallucinationsβ
AI models can generate plausible-sounding but incorrect information:
β Prompt: "What is the population of Mars?"
β Bad Output: "The population of Mars is approximately
150,000 as of the latest census data."
This is completely fabricated but sounds confident!
Prevention Strategies:
- Ask for sources
- Verify critical facts
- Use prompts that encourage uncertainty acknowledgment
3. Context Window Limitsβ
Each model has a maximum amount of text it can process:
| Model | Context Window | Practical Meaning |
|---|---|---|
| GPT-3.5 | 4K-16K tokens | ~6-24 pages |
| GPT-4 | 8K-128K tokens | ~12-192 pages |
| Claude 3 | 200K tokens | ~300 pages |
4. Reasoning Limitationsβ
While impressive, AI reasoning has gaps:
- Struggles with complex multi-step math
- Can be fooled by tricky logic puzzles
- May not understand implicit context
- Can be inconsistent across similar questions
5. Bias and Safetyβ
Models may reflect biases in their training data:
- Cultural biases
- Stereotypes
- Potential for harmful content
Choosing the Right Modelβ
Decision Frameworkβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WHICH MODEL SHOULD I USE? β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Is the task complex (analysis, coding, reasoning)?
ββ YES β Is cost a major concern?
β ββ YES β Claude 3 Sonnet or GPT-4 Turbo
β ββ NO β GPT-4 or Claude 3 Opus
β
ββ NO β Is speed critical?
ββ YES β GPT-3.5 Turbo or Claude 3 Haiku
ββ NO β Do you need privacy/local hosting?
ββ YES β Llama 3 or Mistral
ββ NO β GPT-3.5 or Claude 3 Sonnet
Task-Based Recommendationsβ
| Task | Recommended Model | Why |
|---|---|---|
| Complex coding | GPT-4, Claude 3 Opus | Best reasoning |
| Quick answers | GPT-3.5, Haiku | Speed + cost |
| Long documents | Claude 3 | 200K context |
| Customer chatbots | GPT-3.5, Sonnet | Balance of quality/cost |
| Private data | Llama 3 | Self-hosted option |
| Creative writing | GPT-4, Claude 3 | Nuanced outputs |
Practical Exerciseβ
Exercise: Model Testingβ
Try the same prompt across different models and compare outputs:
Test Prompt:
Explain quantum computing to a 10-year-old in 3 sentences,
then explain it to a physics PhD student in 3 sentences.
Compare:
- Quality of simplification
- Technical accuracy
- Tone adjustment
- Overall helpfulness
Key Takeawaysβ
- LLMs predict text token by token based on training data
- Major models include GPT-4, Claude 3, Llama 3, and Gemini
- Each model has strengths: GPT-4 (reasoning), Claude (context), Llama (privacy)
- Limitations are real: hallucinations, knowledge cutoffs, reasoning gaps
- Choose based on task: Consider complexity, cost, speed, and privacy needs
What's Next?β
Congratulations! You've completed Module 1. Now it's time to test your knowledge with the Module 1 Quiz.
β Previous: Why Prompt Engineering Matters | Take the Quiz β