# Week 4 Lecture 1

## Models & Context

---

# 📆 Week 4

- Today: Giving AI context
- Thursday: [Project 3](../../projects/03/project-3.project.md) due by 2:30pm on Thursday
- Thursday: Begin work on Project 4 using [Codex](../../resources/chatgpt-desktop.guide.md)

---

<!-- id: this-week-in-ai -->

<x-sfx-cue src="../assets/this-week-in-ai-theme.mp3" on="player:block-enter" />

![@image(fit=contain).background](../assets/this-week-in-ai.png)

<!-- [This week in AI](../assets/this-week-in-ai.png) -->

---

## Pacing the Frontier and more X-risk panic

---

[@embed altman + dario pacing the frontier](https://x.com/sama/status/2098811563415150910?s=20)

[@embed Dario Amodei on pacing the frontier](https://darioamodei.com/post/we-must-pace-the-frontier)

---

![time cover](../assets/time-cover.jpeg)

---

[@embed Sneha on Fox](https://x.com/SnehaRevanur/status/2099875567554449409?s=20)

---

![hack these targets](../assets/hack-these-targets.png)

---

[@embed dept. of war resp](https://x.com/DoWCTO/status/2099536442594582922?s=20)

---

![trump take](../assets/trump-take.png)

---

[@embed effective altruism](https://x.com/antonintscalia/status/2099611315589312702?s=20)

See [Effective Altruism](../../codex/effective-altruism.concept.md) for more details.

---

## AI and Mathematics

[@embed Misalignment of AI and Mathematics](https://x.com/AndrewCurran_/status/2098493108224950438?s=20)

[@embed Math and AI](https://mathandai.org/)

---

# Models & Context

---

# Two places a model "knows" things

- **Weights:** what it learned in training. Frozen until the next training run.
- **Context:** what you give it right now. Prompt, files, tools, conversation.

^ This is the whole lecture. Training is rare and expensive. Context is every request.

---

# Models

A **model** is a function that turns input into a prediction.

- **Large language models (LLMs):** read and write text, one token at a time
- **Embedding models:** place text on a map of meaning (search, "find similar")
- **Multimodal models:** also take images, audio, or video as input
- **Generative media models:** make images, audio, or video
- **Reward models:** score answers so another model can be trained

^ Students already met tokens, embeddings, and parameters in week 2. Today we add _where the knowledge lives_.

---

# The model you chat with is a stack

Same architecture. Different data, different job.

^ Pre-training teaches language. Fine-tuning and RLHF teach _behavior_.

---

```mermaid
flowchart LR
  P[Pre-training] --> F[Fine-tuning]
  F --> R[RLHF]
  R --> C[Chat model]
```

---

# Model training: pre-training

1. Collect a huge corpus: web, books, code, conversations
2. Break it into [tokens](../../resources/course.glossary.md)
3. Train the model to guess the **next token**, billions of times
4. Spend weeks and a fortune in GPUs
5. Get a **base model**: fluent, not helpful

^ GPT-3 was famous as a base model. It could complete text. It was not ChatGPT.

---

# What pre-training buys you

- Grammar, style, and a lot of world knowledge
- Patterns of code, math, and argument
- **No** knowledge of _your_ files, _today's_ dining hall, or _this_ assignment
- Weights do not update when you talk to it

^ If the answer has to be current or personal, it cannot live in the weights.

---

## Fine-tuning

Take the base model. Train it a little more on a **small, curated** set.

- Show examples of the behavior you want: instruction → good answer
- Can specialize: "write like a tutor," "only output JSON," "review this kind of code"
- Much cheaper than pre-training
- Still changes the **weights**, not the prompt

^ This is [supervised fine-tuning](../../resources/course.glossary.md) (SFT). A chat model is a base model that was fine-tuned to follow instructions.

---

## Reinforcement Learning from Human Feedback (RLHF)

How we got from "predict the next word" to "be a good assistant."

1. The model writes several answers to the same prompt
2. People rank them: better / worse
3. A **reward model** learns those preferences
4. The LLM is trained to produce answers the reward model likes

^ [Dario Amodei](../../codex/dario-amodei.person.md) helped invent this at OpenAI. InstructGPT (2022) is the classic example. See [RLHF](../../resources/course.glossary.md).

---

## After RLHF: checkable rewards

Today's reasoning models add a second loop:

- For **math and code**, you often do not need a human ranker
- The compiler, the test, or the answer key can score the attempt
- The model practices until the check passes

^ This is why o1-style models "think" before they talk. The preference for _verified_ answers got trained in.

---

# Context

## Getting the right information at the right time.

---

**Context:** The information available to the agent when it decides what to do next.

- System instructions
- Your prompt
- Files, tools, and retrieved facts
- The conversation so far — until the [context window](../../resources/course.glossary.md) fills

^ Weights are the long-term memory of the species. Context is working memory for this task.

---

**Agent:** a person, entity, or substance that has the power to act or that represents another person or organization

---

**Human Agency**: a mindset and ability to proactively shape your circumstances and get things done instead of letting life happen to you passively.

^ One of the most important traits you can develop!

---

**AI Agent:** an autonomous software system designed to perceive its environment, make decisions, and take actions to achieve specific goals

---

## AI Agency vs. Human Agency

- Humans can proactively act generally in the world (AGI)
- AI agents are constrained by the context, tools, model and environment

---

**Harness:** a tool or system that allows an agent to interact with its environment and achieve its goals

---

**AI Harness:** a tool or system that allows an AI agent to interact with its environment and achieve its goals

---

**AI Agent Harness:** context + tools

^ Last Thursday: the harness is the wrapper. Today: the quality of the work is usually the quality of the context.

---

## What context do we need?

- How busy is DH right now?
- What do I need to do to complete Project 3?
- Do I have time to go to the game on Friday afternoon?
- Should I ask `<person>` out?

---

## Same questions, missing information

| Question          | The model already knows  | What it still needs                        |
| ----------------- | ------------------------ | ------------------------------------------ |
| How busy is DH?   | What a dining hall is    | Live occupancy, right now                  |
| Finish Project 3? | What a brief looks like  | The assignment, _your_ draft, the deadline |
| Friday game?      | Typical campus schedules | _Your_ calendar, kickoff, travel time      |
| Ask someone out?  | Generic dating advice    | Almost everything that actually matters    |

^ Walk these. The last one is the joke with a point: some context is human, and should stay that way.

---

```mermaid
flowchart TD
  Q[A real question] --> C{Is the needed info in context?}
  C -->|No| G[The model guesses from training]
  C -->|Yes| A[The agent can decide and act]
```

Guessing from weights looks fluent. It is still a guess.

---

# Context is a portable idea

A good brief is context you can hand to **any** agent.

If it only works inside one chat, it is not context yet. It is leftover conversation.

^ This is the Project 3 test: a new agent, no history, can still tell what to build.

---

```mermaid
flowchart LR
  B[One-page brief] --> X[Codex]
  B --> Y[Claude Code]
  B --> Z[Cursor]
  X --> P[Same first version]
  Y --> P
  Z --> P
```

---

# Your job as the human

- Decide what the agent is for
- Gather the facts it cannot know
- Distill them so another model could execute the idea
- Keep the judgment that should stay yours

^ Agency is choosing the context. The model just runs it.

---

[Prompt Lab](../../labs/prompt.lab.md)

---

[Project 3 Work](../../projects/03/project-3.project.md)

^ New example briefs are up. Read one as if you were a new agent with no chat history.
