← Advanced Data Science

Week 7 Building and Evaluating AI Systems

Foundation Models, Adaptation, and PBL1 Defense

Foundation models learn reusable representations from broad pretraining objectives. Their apparent flexibility comes with inherited data limits, objective mismatch, prompt sensitivity, and substantial evaluation obligations.

Core question: Why do foundation models behave differently, and what evidence supports an adaptation choice?

PretrainOptimize a broad prediction objective over large, imperfect corpora.
AdaptChange context, retrieval, heads, or selected parameters for a task.
DefendEvaluate task behavior, failures, provenance, cost, and responsibility.

By the end

  • Distinguish causal language modeling from masked representation learning.
  • Compare prompting, retrieval, feature extraction, parameter-efficient adaptation, and full fine-tuning.
  • Calculate adaptation parameters and identify evidence needed before changing a model.
  • Defend PBL1 model-behavior claims with individual accountability.

Course progression

Build one evidence chain

This week uses the course-wide sequence: frame the use, establish a baseline, build or compare, evaluate failure, document boundaries, and decide.

framebaselinebuildevaluatedocumentdecidemonitor
Connection from the course

Week 8 begins the system half of the course by adding inspectable retrieval and provenance around a generator.

Essential concepts

Understand the parts before combining them

The core lane focuses on transferable judgment. Optional formal or engineering depth belongs in the companion notebook's stretch lane.

Causal objective

An autoregressive model predicts the next token from earlier tokens. It is naturally generative but is not trained to verify truth.

Masked objective

An encoder reconstructs hidden tokens using both left and right context. It produces contextual representations suited to understanding tasks.

Adaptation ladder

Prompting changes instructions; retrieval changes context; feature extraction adds a head; PEFT changes a small parameter set; full fine-tuning changes the base model.

Mathematical intuition

One relationship worth keeping

\[\mathcal{L}_{\mathrm{causal}}=-\sum_{t=1}^{T}\log p_\theta(x_t\mid x_{\lt t})\]

The objective rewards likely continuation of training-like text. Factuality, safety, calibration, and task utility require separate evidence.

Stretch: what the notation leaves out

A next-token objective can produce fluent unsupported statements because likelihood under the learned distribution is not the same as source-grounded truth.

Interactive explorer

Change assumptions and inspect the decision

Change labeled-data volume, knowledge freshness, and compute budget. Which adaptation rung deserves testing first?

Current signal
Recommended response

Fresh knowledge favors retrieval; few labels and little compute favor prompting or feature extraction; PEFT needs task data; full fine-tuning needs strong evidence and resources.

Evidence workflow

Move from a claim to a decision

Use this order in the chapter, notebook, and project record. Skipping an earlier step weakens every later claim.

  1. 1. Define the task, baseline, failure costs, privacy, and knowledge horizon.
  2. 2. Start at the lowest adaptation rung that could satisfy the task.
  3. 3. Freeze prompts, retrieval sources, templates, and model versions as testable components.
  4. 4. Compare quality, robustness, latency, cost, and failure slices.
  5. 5. Document the rejected alternatives and why the chosen rung is sufficient.
Weekly evidence artifact

PBL1 team dossier, demonstration, and sampled individual defense

Project connection

Complete PBL1 with a frozen model-behavior audit, peer challenge, demonstration, AI-use ledger, and sampled individual defense.

Failure analysis

Deliberately look for the claim's boundary

A failure case is useful when the setup, expected behavior, observation, severity, and response are recorded.

Objective confusion

Failure: Fluency is treated as proof of understanding or truth.

Evidence: Source checks reveal unsupported claims.

Response: Separate generation quality from factual support and decision utility.

Fine-tuning by default

Failure: A model is adapted before a baseline, prompt, or retrieval test.

Evidence: The complex approach lacks incremental evidence.

Response: Move down the ladder and compare under one evaluation set.

Contaminated defense

Failure: A team reports the best score without the full trial history.

Evidence: Experiment records reveal selective reporting.

Response: Preserve all trials and require individual explanation of one failure and correction.

Use and non-use

Keep authority proportional to evidence

Intended use

Use foundation models as components when their objective and adaptation are matched to a tested task.

Do not use

Do not delegate truth, authorization, or consequential judgment to fluent output.

Human responsibility

A human approves data, adaptation level, release claims, and PBL evidence integrity.

Small Python demonstrations

Predict, run, and interpret

Each button calls one fixed, allowlisted computation. Use the notebook for longer experiments and saved evidence.

Compute token loss

import math
probabilities = [0.7, 0.5, 0.8]
loss = -sum(math.log(p) for p in probabilities)/len(probabilities)
print(round(loss, 3))
output

Run this fixed example to compare your prediction with the result.

Compare visible context

tokens = ["data", "needs", "evidence", "today"]
print("causal target context:", tokens[:2])
print("masked target context:", [tokens[0], tokens[2], tokens[3]])
output

Run this fixed example to compare your prediction with the result.

Count LoRA parameters

d_in, d_out, rank = 768, 768, 8
full = d_in*d_out
lora = rank*(d_in+d_out)
print("full:", full)
print("LoRA:", lora, "ratio:", round(lora/full, 4))
output

Run this fixed example to compare your prediction with the result.

Check your understanding

Ten questions with standard answers

Answer before opening each panel. A good answer connects the concept to evidence, failure, and a bounded decision.

1. Why do foundation models behave differently, and what evidence supports an adaptation choice?

Standard answer: Foundation-model behavior follows broad prediction objectives and inherited data; choose the lowest adaptation rung that passes a task-specific evaluation and boundary review.

2. What is the role of causal objective in this chapter?

Standard answer: An autoregressive model predicts the next token from earlier tokens. It is naturally generative but is not trained to verify truth.

3. Why does masked objective require evidence rather than intuition?

Standard answer: An encoder reconstructs hidden tokens using both left and right context. It produces contextual representations suited to understanding tasks.

4. How should a practitioner use adaptation ladder?

Standard answer: Prompting changes instructions; retrieval changes context; feature extraction adds a head; PEFT changes a small parameter set; full fine-tuning changes the base model.

5. What does the chapter's main formula clarify—and what does it not prove?

Standard answer: A next-token objective can produce fluent unsupported statements because likelihood under the learned distribution is not the same as source-grounded truth.

6. What should change in the explorer as its risk or complexity controls increase?

Standard answer: Fresh knowledge favors retrieval; few labels and little compute favor prompting or feature extraction; PEFT needs task data; full fine-tuning needs strong evidence and resources.

7. How should the system respond to: Objective confusion?

Standard answer: Separate generation quality from factual support and decision utility.

8. What evidence reveals the failure called Fine-tuning by default?

Standard answer: The complex approach lacks incremental evidence.

9. When should the system not be used or allowed to proceed?

Standard answer: Do not delegate truth, authorization, or consequential judgment to fluent output.

10. How does this week prepare the next stage of the course?

Standard answer: Week 8 begins the system half of the course by adding inspectable retrieval and provenance around a generator.

Terminology

Glossary

Foundation model
A broadly pretrained model adapted or prompted for multiple downstream uses.
Causal language model
A model trained to predict tokens from earlier context.
Masked language model
A model trained to reconstruct hidden tokens using surrounding context.
Pretraining
Broad learning before a specific downstream task is fixed.
Prompting
Specifying instructions and context without changing model parameters.
Feature extraction
Using frozen representations with a task-specific predictor.
Fine-tuning
Updating pretrained parameters using downstream data.
PEFT
Parameter-efficient fine-tuning that changes a small parameter subset or adapters.
LoRA
Low-rank adaptation using trainable low-rank update matrices.
Contamination
Evaluation information appearing in training, prompts, or repeated model-selection feedback.

Continue learning

Key references

These primary papers, standards, or official technical documents anchor the chapter. Product names and current legal timelines should be rechecked when used in a real project.