Exercises — Responsible AI deployment practices
This page leans on ideas from 6.4.1-Adversarial-examples, 6.4.8-Fairness-metrics, 6.4.12-Explainability-methods, 6.3.2-MLOps-principles, 5.2.4-A-B-testing, and 6.4.14-AI-governanceframeworks. Prefer the Hinglish version? Yeh page Hinglish mein →.
Symbols You Will Need (built once, used everywhere)
Keep these definitions in view. Every problem below is one of these tools answering one clear question.
Level 1 — Recognition
Exercise 1.1
Match each safeguard to the failure it prevents: (a) Shadow mode, (b) Circuit breaker, (c) Staged rollout, (d) Confidence-based routing. Failures: (i) a rare edge case wiping out all users at once, (ii) users seeing a broken new model at all, (iii) a burst of adversarial inputs cascading into thousands of bad decisions, (iv) a low-confidence prediction acted on with no human check.
Recall Solution
- (a) Shadow mode → (ii). The new model runs in parallel but its output is never shown to users, so a failure has zero user impact.
- (b) Circuit breaker → (iii). It "trips" after a burst of low-confidence/error signals, capping the blast radius (defined above).
- (c) Staged rollout → (i). Growing the audience slowly means a rare edge case first hits a small population.
- (d) Confidence-based routing → (iv). Below-threshold predictions are handed to a human. Why this matters: these are the three pillars — pre-deployment (c, a), runtime (b), oversight (d) — each catching a different failure mode. The figure below places each safeguard on the deployment timeline so you can see where each shrinks the blast radius.

The diagram reads left to right along the deployment lifecycle. Staged rollout (lavender) and shadow mode (mint) act before users are exposed; the widening funnel shows the audience growing only after each gate passes. The circuit breaker (coral) sits at runtime, clamping a spike of failures. Confidence routing (butter) peels off uncertain cases to a human. The shaded "blast radius" band shrinks each time a safeguard intervenes.
Exercise 1.2
In the formula , which symbol is the "acceptable chance of missing a real failure"? Which is the "failure rate"?
Recall Solution
- = acceptable miss chance (e.g. ).
- = the failure rate we hope to catch (e.g. ). (samples needed) rises when shrinks (rarer bugs need more looks) and when shrinks (more certainty needs more looks).
Level 2 — Application
Exercise 2.1
You suspect a failure rate of (). You want a chance of catching it (). How many samples must the stage observe?
Recall Solution
WHAT: plug into . WHY this formula: the chance of zero failures in independent tries is ; we force that to be at most , then solve for . Round up (you cannot observe a fractional request): samples. If daily volume at this stage is users, that is days.
Exercise 2.2
An image classifier over classes outputs probabilities on a request. Compute the prediction entropy (base-2, so the answer is in "bits" — matching the convention fixed in the Symbols box).
Recall Solution
WHY entropy here: we want a single number for "how unsure is this guess?" A confident guess should score low. Read the figure below to place this number on a scale: the mint bar is a totally sure guess with ; the coral bar is total confusion with bits; our butter bar at sits between them — moderately confident. The visual makes concrete why a rising average entropy in production (Exercise 3.2) is an alarm: the bars are sliding rightward toward confusion.

Exercise 2.3
Training feature histogram over bins: . This week's production histogram: . Compute (base-2, bits — same convention).
Recall Solution
WHY KL here: it scores "how surprised is a model tuned on when it meets ." Bigger = more drift. Note the middle bin contributes zero (it did not move) and the shrinking bin contributes a negative term — but the growing bin outweighs it, so the total is positive, as KL always is. Edge-case reminder: here every , so the sum is well-defined. Had a production bin been empty () while training saw it (), that term would be and would be undefined — which is why real monitors Laplace-smooth first (see Symbols box).
Level 3 — Analysis
Exercise 3.1
A content-moderation model in shadow mode over one week:
- Old model false-positive rate: .
- New model false-positive rate: .
- But new-model false positives split: on non-English names, on English names.
Should you promote the new model to traffic? Justify using a fairness lens.
Recall Solution
No. The aggregate metric () hides a disparity. Using the demographic-parity idea: the false-positive rate differs by group. The ratio — a -to- gap far beyond a "within " parity gate. Diagnosis: English-biased training data taught the model "uncommon character sequences spam," so names like Xiang or Aditya trip false positives. A lower average error was bought at the expense of a subgroup. Action: do not promote. Return to training with multilingual name dictionaries as protected features; re-run the shadow comparison sliced by group before any staged rollout.
Exercise 3.2
An image classifier's average entropy readings: Train , Week 1 , Week 4 (bits). Interpret the trend and name the likely cause. What specific runtime metric would confirm it?
Recall Solution
Rising entropy = the model is getting less sure on average = it is meeting inputs it was not trained on (out-of-distribution). Week 1's tiny rise () is noise; Week 4's jump to (nearly doubled) is a red flag 🚨. Likely cause: a distribution shift — e.g. seasonal change (bare winter trees in training vs. blossoming spring trees now). This is data drift. Confirming metric: compute on the input features. If it also spikes past its threshold, drift is confirmed and a retrain is justified. Entropy tells you the model is unsure; KL tells you the inputs actually changed — you want both to agree before acting.
Level 4 — Synthesis
Exercise 4.1
Design a circuit breaker for a spam classifier. Requirements:
- Treat a prediction as an "error" if its confidence .
- Trip (open) when the error rate over the last predictions exceeds .
- Under attack, of a stream of adversarial emails have confidence .
(a) After how many emails does the breaker trip? (b) How many bad emails reach users before the trip, and how many are saved by routing the rest to humans? (c) Specify the full state machine — including startup, reset, and cooldown.
Recall Solution
(a) When does it trip? — explicit answer. The breaker compares the error rate over the last predictions against , i.e. it trips once more than of the trailing are errors ( or more). With a steady error rate the errors arrive at a rate of per email. To accumulate errors we expect to need emails — but the window must contain predictions before a "last-100" rate is even defined, and by the time the th email is processed the window holds errors, which is already . So under the steady-rate assumption the very first moment a full trailing window exists () it already shows errors and trips. Explicit answer: the breaker trips at the th email (the earliest point at which a full -prediction window exists, at which point it is already over threshold).
(b) Blast radius — explicit numbers.
- Emails the model actually processed before tripping: .
- Of those, misclassified (low-confidence errors served): bad emails reached users.
- Emails routed to human reviewers after the trip: emails (all remaining traffic goes to fallback).
- Bad emails prevented among those : likely errors avoided. Contrast: with no breaker, all emails hit the model and are misclassified. The breaker cuts served errors from down to — a reduction in blast radius.
(c) The full state machine — startup, cooldown, and an explicit RESET. The diagram below shows every state and transition; each is spelled out here.
- CLOSED (normal): the model serves predictions; each is logged into a sliding window of the last events.
- Startup rule (from the problem statement, no invented hyperparameter): the trip condition is "error rate over the last predictions exceeds ." Taken literally, that rate is only defined once predictions exist. Therefore the breaker cannot trip before the window is full () — the startup behaviour is simply "stay CLOSED until the trailing- window exists." This falls directly out of the given requirement; we add nothing.
- OPEN (tripped): all traffic goes to the fallback (human reviewers / safe default); no model calls are made. A cooldown timer runs (a fixed wait, e.g. s or events) during which the breaker refuses to touch the model at all — this prevents rapid on/off flapping.
- HALF-OPEN (probing, entered automatically when cooldown elapses): the breaker lets a small trial batch through the model. If the trial batch's error rate is back below , it transitions to CLOSED; if still high, it returns to OPEN and restarts cooldown.
- RESET (explicit transition, HALF-OPEN → CLOSED): "reset" is precisely the successful HALF-OPEN probe — the breaker clears its error window and returns to normal CLOSED operation. There is also a manual RESET: an on-call engineer, after fixing root cause, can force OPEN → CLOSED directly (clearing the window), overriding the automatic path. Both are labelled in the diagram. Design note: the sliding window reacts to recent degradation; the startup rule prevents early flapping; cooldown prevents oscillation; the HALF-OPEN probe (auto-reset) plus the manual reset both restore service; and the fallback guarantees users still get some answer. This is the adversarial-robustness safety net in action.
The full state machine (CLOSED → OPEN → HALF-OPEN, plus both reset paths) that the solution specifies:
Exercise 4.2
Design a monitoring dashboard for a hospital diagnosis assistant. For five panels, state the failure mode each catches and a concrete alert trigger. Tie the design back to the three pillars and governance.
Recall Solution
The wireframe below sketches the five panels as an annotated dashboard; the accompanying reasoning is stated per panel underneath.
Panel 1 — Human override rate. Catches: model no longer useful (doctors reject it). Trigger: for h → page on-call. Panel 2 — Feature drift (). Catches: inputs no longer match the training world. Trigger: → queue retrain. Panel 3 — Average confidence / entropy. Catches: model growing uncertain (out-of-distribution). Trigger: entropy up over baseline. Panel 4 — Latency P95. Catches: usability degradation and infra stress. Trigger: P95 s → auto-scale. Panel 5 — Demographic breakdown. Catches: emerging subgroup bias. Trigger: parity gap → block + audit.
Why this maps to the pillars: override rate and demographic breakdown are human-oversight + fairness signals; drift, entropy, latency are runtime monitoring; and every threshold above is a documented, auditable gate — exactly what a governance framework and MLOps discipline demand (each metric traceable, each alert owned).
Level 5 — Mastery
Exercise 5.1
Your rollout budget allows observing at most samples in a stage, and you demand confidence of catching a failure. What is the smallest failure rate you can reliably detect within this budget? Interpret: what does this say about failures rarer than that?
Recall Solution
WHAT: invert the rollout formula for given and . Starting from : Interpretation: with samples you can catch failures down to roughly . Anything rarer (e.g. , one-in-ten-thousand) will slip through this stage undetected with more than a chance — this is the long-tail curse: you cannot test your way to safety against ultra-rare events; you need runtime monitoring and circuit breakers to catch them in the wild.
Exercise 5.2
A confidence-based router sends predictions below threshold to humans. Suppose raising from to increases the human-review load from to of traffic while cutting automated errors from to . Human review costs \0.50$40100{,}000$ daily requests, which threshold is cheaper? Should cost be the only criterion?
Recall Solution
WHAT: total daily cost (human-review cost) (automated-error cost). At : review = 0.12 \times 100000 \times \0.50 = $6000= 0.030 \times 100000 \times $40 = $120000= $126000\tau=0.90= 0.22 \times 100000 \times $0.50 = $11000= 0.018 \times 100000 \times $40 = $72000= $83000\tau = 0.90$43000\tau$ (more human review) than the cost-optimal one, and explainability should accompany each routed case so the human reviewer can decide well. Cost sets a floor for the argument, not the ceiling.
Recall Self-Test Cloze
A staged rollout needs samples because the chance of zero failures in tries is ====, forced . Shadow mode differs from A/B testing because ::: only the old model's output reaches users; the new model is scored silently offline (zero user risk). A rising average entropy signals ::: the model is growing uncertain, likely meeting out-of-distribution inputs (drift). KL divergence is undefined when a production bin is empty because ::: ; we Laplace-smooth to fix it. A circuit breaker returns from OPEN to CLOSED via the ::: HALF-OPEN state (auto-reset probe) or a manual reset by the on-call engineer.