Concept Lesson
Advanced
4 min

Learning Objective

Understand Counterfactuals well enough to explain it, recognize it in Math for LLMs, and apply it in a small task.

Why It Matters

Counterfactuals gives you the math vocabulary behind model behavior, optimization, and LLM reasoning.

CounterfactualsPrerequisitesCompanion NotebooksLearning ObjectivesReading Path
Private notes
0/8000

Notes stay private to your browser until account sync is configured.

Notes
2 min read6 headings6 reading parts

"A counterfactual asks the model to remember what happened and imagine what would have happened instead."

Overview

Counterfactual reasoning studies unit-level alternatives by combining factual evidence with a causal model of interventions.

Causal inference is the part of the curriculum that separates observing from doing. It asks which assumptions allow a learner to move from associations in data to claims about interventions, alternatives, and mechanisms.

This section is written in LaTeX Markdown. Inline mathematics uses $...$, and display equations use `

......

`. The notes emphasize graph assumptions, intervention notation, counterfactual semantics, and the estimand-estimator split.

Prerequisites

Companion Notebooks

NotebookDescription
theory.ipynbExecutable demonstrations for counterfactuals
exercises.ipynbGraded practice for counterfactuals

Learning Objectives

After completing this section, you will be able to:

  • Define SCMs, structural assignments, and intervention distributions
  • Distinguish conditioning from intervention using the do-operator
  • Apply d-separation to simple causal graphs
  • State backdoor and frontdoor adjustment formulas
  • Separate causal estimands from statistical estimators
  • Compute ATE, ATT, and simple counterfactual quantities
  • Explain abduction, action, and prediction in SCM counterfactuals
  • Describe constraint-based and score-based causal discovery
  • Identify assumptions behind causal discovery algorithms
  • Connect causal inference to robust ML, fairness, recommendation, and LLM agents

Study Flow

  1. Read the pages in order and pause after each page to restate the main definition or theorem.
  2. Run theory.ipynb when you want to check the formulas numerically.
  3. Use exercises.ipynb after the reading path, not before it.
  4. Return to this overview page when you need the chapter-level navigation.

Runnable Companions

Skill Check

Test this lesson

Answer 4 quick questions to lock in the lesson and feed your adaptive practice queue.

--
Score
0/4
Answered
Not attempted
Status
1

Which module does this lesson belong to?

2

Which section is covered in this lesson content?

3

Which term is most central to this lesson?

4

What is the best way to use this lesson for real learning?

Your answers save locally first, then sync when account storage is available.
Practice queue