← Back to Tutorials

9. ChatGPT & Large Language Models

Generative AI in Practice

What are LLMs?

Large Language Models (LLMs) are neural networks with billions of parameters trained on massive text corpora. They can generate coherent text, answer questions, translate languages, write code, and more — all by predicting the next token autoregressively.

ChatGPT Training Pipeline

  1. Pre-training — GPT model trained on internet text (next token prediction). This is the most expensive stage, consuming thousands of GPUs for weeks.
  2. Supervised Fine-Tuning (SFT) — Fine-tune on high-quality (prompt, response) pairs crafted by human labelers
  3. Reward Modeling — Train a reward model on human preferences (rankings of outputs)
  4. RLHF (PPO) — Optimize the SFT model against the reward model with a KL penalty for stability

Prompt Engineering

Techniques to get better outputs from LLMs:

# Prompt template
prompt = """You are a helpful coding assistant.
Explain the following code in simple terms:

```
def fibonacci(n):
    if n <= 1: return n
    return fibonacci(n-1) + fibonacci(n-2)
```
"""

Capabilities

Limitations

Practice Task: Use an LLM API (ChatGPT, Claude, or open-source via Ollama) to experiment with prompting. Compare the quality of zero-shot vs few-shot prompts for a specific task (e.g., classifying email sentiment). Try chain-of-thought prompting on a math problem. Document the prompts, outputs, and what you learned about prompt design.