Skip to main content

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​

ConceptExplanationWhy It Matters
TokenBasic unit of text (roughly 4 characters)Affects pricing and context limits
Context WindowMaximum input + output lengthDetermines how much info AI can consider
ParametersModel's learned weights (billions)More parameters often = more capable
TemperatureRandomness in outputHigher = more creative, Lower = more consistent
Training DataText the model learned fromAffects 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
Why This Matters

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​

FeatureDetails
CompanyOpenAI
Context Window8K-128K tokens
StrengthsReasoning, coding, general knowledge
Best ForComplex tasks, analysis, creative writing
AccessChatGPT 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​

FeatureDetails
Context Window4K-16K tokens
StrengthsSpeed, cost-efficiency
Best ForSimple tasks, high-volume applications
Cost~20x cheaper than GPT-4

Anthropic Models (Claude Family)​

Claude 3 (Opus, Sonnet, Haiku)​

VariantStrengthUse Case
OpusMost capableComplex analysis, research
SonnetBalancedGeneral purpose, coding
HaikuFastest, cheapestQuick 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​

FeatureDetails
CompanyMeta
LicenseOpen source (mostly)
Sizes7B, 13B, 70B parameters
StrengthsCustomizable, self-hostable, free
LimitationsLess capable than GPT-4/Claude 3

Best For:

  • Organizations needing data privacy
  • Custom fine-tuning
  • Cost-sensitive applications
  • Research and experimentation

Other Notable Models​

ModelCompanyNotable Feature
GeminiGoogleMultimodal, integrated with Google services
MistralMistral AIHigh quality open-source alternative
CommandCohereEnterprise-focused, RAG optimized
GrokxAIReal-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:

ModelApproximate Cutoff
GPT-4April 2023 (varies)
Claude 3Early 2024
Llama 3December 2023
Implication

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:

ModelContext WindowPractical Meaning
GPT-3.54K-16K tokens~6-24 pages
GPT-48K-128K tokens~12-192 pages
Claude 3200K 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​

TaskRecommended ModelWhy
Complex codingGPT-4, Claude 3 OpusBest reasoning
Quick answersGPT-3.5, HaikuSpeed + cost
Long documentsClaude 3200K context
Customer chatbotsGPT-3.5, SonnetBalance of quality/cost
Private dataLlama 3Self-hosted option
Creative writingGPT-4, Claude 3Nuanced 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:

  1. Quality of simplification
  2. Technical accuracy
  3. Tone adjustment
  4. Overall helpfulness

Key Takeaways​

Summary
  1. LLMs predict text token by token based on training data
  2. Major models include GPT-4, Claude 3, Llama 3, and Gemini
  3. Each model has strengths: GPT-4 (reasoning), Claude (context), Llama (privacy)
  4. Limitations are real: hallucinations, knowledge cutoffs, reasoning gaps
  5. 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 β†’