Phase 04 · Week 13 · 105 minutes

Day 89: Overfitting, leakage, augmentation, and baselines

PyTorch through robot data · Learn deep learning by predicting robot-relevant outputs.

Chapter 13 · Build a trustworthy PyTorch experiment from robot-shaped data

Today in the field story

One problem, then the next

The scout performs well until lighting changes, suggesting it learned a production-burst shortcut. Inspect the worst held-out crops, compare against the simple baseline, and test physically plausible brightness or crop changes without corrupting label meaning. Keep the final test sealed while repairing development failures. More augmentation is not automatically more evidence; each transform needs a reason tied to a condition the camera can produce.

Why now

Optimization success must be challenged for leakage, shortcut learning, and overfitting.

Ignore today

Ignore broad robustness claims; diagnose one supported failure and one controlled response.

Unlocks next

A candidate whose improvement survives a realistic held-out condition.

Understand

Build the physical picture first

A model can ace practice by reading a smudge on the answer sheet; only a clean exam and broken-shortcut trials reveal whether it learned the robot task.

Optimization error asks how well the model fits examples used to update it. Generalization asks how well the chosen frozen model performs on relevant examples not used for those updates. Overfitting appears when training performance improves while held-out performance stalls or worsens, but the gap alone does not name the cause. Capacity, too little varied data, label noise, repeated near-duplicates, excessive tuning, and a distribution mismatch can all contribute. Plot train and validation metrics against the same checkpoint sequence and inspect actual errors rather than diagnosing from one final number.

Leakage makes an exam easier by letting information cross the intended boundary. Adjacent robot video frames in both splits, normalization fit on all images, selecting examples after seeing test errors, or tuning repeatedly to the test set can each contaminate evaluation. A test set is not a second validation set. Freeze group identities and preprocessing lineage, use validation for limited model decisions, and evaluate the test set at the declared final boundary. If leakage is found, repair the split and invalidate the affected results instead of subtracting an imagined leakage amount.

A shortcut is a feature correlated with the answer in collected data but unreliable for the intended task. If every red block appears on a blue mat and every green block on a grey mat, a visual model may classify the mat. Condition slices, occlusion tests, background swaps, and error contact sheets can expose this behavior. Augmentation can add plausible variation, but it cannot repair a leaked split or invent missing physics. A horizontal flip may require changing an x-coordinate sign or may be invalid for an asymmetric gripper, so every augmentation needs a target-consistency and physical-validity argument.

A baseline tells whether learned complexity earns its cost. For numeric pose targets, always predicting the training mean is a useful lower bar; a linear model may be stronger. Compare on identical frozen splits and physical metrics. If the complex model has validation MSE 0.30 while the mean baseline has 0.28, the model is worse on that metric even if its training MSE is 0.05. Also compare condition slices, worst errors, latency, memory, and safe rejection because a small average improvement can hide a robot-critical regression.

Words you need

Name each idea precisely

Overfitting

Learning training-specific detail that lowers training error without improving relevant held-out performance.

Physical example:

A cup locator memorizes backgrounds from eight collection scenes and misses the same cup on a new table.

Generalization gap

A difference between comparable held-out and training metrics, useful as a symptom but not a complete diagnosis.

Physical example:

Training MSE 0.05 and validation MSE 0.30 give a gap of 0.25 under the same scaling and target definition.

Data leakage

Any path by which evaluation examples or information influence fitting, preprocessing, model selection, or repeated tuning.

Physical example:

Frames one timestamp apart from the same grasp appear in train and validation, making the held-out scene nearly familiar.

Shortcut

A predictive pattern in the collected dataset that is easier than the intended task and unreliable under deployment changes.

Physical example:

The model uses table color to infer block class because collection never varied that background.

Augmentation

A label-consistent, physically defensible training transformation that expands observed variation without pretending to be new independent evidence.

Physical example:

A small brightness change may model lighting variation, while a mirror flip must also transform pose targets and respect robot asymmetry.

Baseline

A simple reproducible method that a more complex model must beat under the same data and metric contract.

Physical example:

Always predicting the training-set mean cup position provides a zero-learning regression baseline.

Math, one line at a time

Work through today’s relationship

Prerequisite rescue · optionalTensor shapes and gradient descent

Most robot-learning bugs are shape, scale, split, or optimization mistakes.

B×T×D
batch, time steps, and feature dimensionsUnit: counts
L
loss measuring prediction errorUnit: task-dependent
η
learning rateUnit: unitless scale
  1. A batch has B=8 episodes, T=20 time steps, and D=12 features.

  2. The tensor contains 8×20×12 = 1,920 numbers.

  3. An optimizer updates a weight with w_new = w_old − η∂L/∂w; inspect shape and finite values before training.

Programmer analogy

Tensor shapes are explicit multidimensional array contracts: every axis has a declared meaning and size.

How many values are in a 4×10×6 tensor?

4×10×6 = 240 values.

The generalization gap is

MSEvalMSEtrain=0.300.05=0.25.\mathrm{MSE}_{\mathrm{val}}-\mathrm{MSE}_{\mathrm{train}}=0.30-0.05=0.25.

A baseline MSE of 0.280.28 is lower than the complex model’s 0.300.30. MSE alone still requires rollout and bad-case inspection.

Reject a complex model that loses to its baseline

On one frozen episode-grouped split, a neural model has training MSE 0.05 and validation MSE 0.30. A mean-target baseline, fitted only on training targets, has validation MSE 0.28.

  1. Confirm all three MSE values use the same target scaling, examples, aggregation, and squared unit; otherwise subtraction would compare different quantities.

  2. Calculate the neural model’s generalization gap: 0.30 - 0.05 = 0.25.

  3. Compare held-out methods: the neural model’s 0.30 is 0.30 - 0.28 = 0.02 worse than the baseline.

  4. Do not call the 0.05 training score a win; it only shows that optimization fit the training examples more closely.

  5. Inspect scene slices and changed predictions for a shortcut, near-duplicate leakage, target error, or condition absent from training.

  6. Keep the baseline as the current choice under this metric, repair the highest-evidence data defect, freeze a new version, and rerun without changing the old result.

Result

The model overfits by a 0.25 train-to-validation gap and fails to beat the baseline by 0.02 validation MSE, so the evidence does not justify its complexity.

What this proves

Held-out comparison against a simple baseline outranks impressive training fit, and a leaked result must be replaced rather than cosmetically adjusted.

Physical examples

Where this appears in real life

Colored-mat shortcut

Place red paper blocks only on a blue sheet and green blocks only on a grey sheet, then cover each block while asking a partner to guess its color.

Look for:

The partner can answer from the background alone; swapping mats breaks the shortcut without changing the actual block identity.

Nearly identical exam photos

Take a short burst of a stationary toy, put alternating photos into practice and exam piles, then compare them with an exam pile from a new room.

Look for:

Alternating burst frames make the first exam almost a copy of practice, while room-level grouping tests a meaningful scene change.

Hands-on exercise

Make the idea observable

Use generated shapes or non-sensitive saved examples. Construct one deliberate background shortcut and perform only offline model or paper analysis.

  1. Create grouped train and validation examples in which a target shape and background color are correlated, then record the intended feature and the shortcut feature.

  2. Fit a simple baseline and tiny model on the same frozen train groups; log training and validation metrics for every checkpoint rather than only the best run.

  3. Evaluate the selected checkpoint on the original validation set, a background-swapped slice, and a target-occluded slice; retain all predictions and example IDs.

  4. Add one physically valid training augmentation with matching target transformation where required, and assert validation examples remain deterministic and unchanged.

  5. Deliberately introduce adjacent-frame or group leakage, measure the optimistic change, then repair the split and mark the contaminated number invalid.

  6. Save curves, baseline table, condition slices, contact sheet, split and transform versions, chosen checkpoint rule, worst cases, and the next data-collection hypothesis.

Observe

The shortcut-trained model degrades when backgrounds swap or targets are hidden, leaked validation looks falsely easier, and a baseline can outperform a model with excellent training fit.

Done when

A reviewer can identify the shortcut from examples and slices, prove group isolation, reproduce the 0.25 gap, and see a decision based on held-out evidence rather than training loss.

Build today

Train a small image-to-pose or observation-to-action network with a reproducible experiment report.

Evidence to save

DONE when a comparison table for “Overfitting, leakage, augmentation, and baselines” contains the test condition, metric, result, and justified engineering decision.

Common mistakes

Catch the wrong mental model

Wrong

Treating a large generalization gap as proof of one specific cause.

Better

Use the gap as a symptom, then inspect duplicates, groups, labels, conditions, learning curves, capacity, and individual errors before naming the cause.

Wrong

Applying more augmentation after discovering train-validation leakage.

Better

Invalidate the contaminated evaluation, repair the group and preprocessing boundary first, then justify augmentation independently.

Wrong

Reporting that a neural model learned because its training loss beats a baseline.

Better

Compare both methods on identical untouched examples, physical metrics, condition slices, worst cases, latency, and rejection behavior.

Job connection

How this becomes employable evidence

Investigate a robot perception or policy regression by auditing group leakage, preprocessing lineage, shortcut slices, baseline performance, augmentation validity, and individual worst cases before approving retraining.

Relevant target roles

  • Robot Learning Deployment / Physical AI Integration Engineer
  • Robotics Deployment, Integration & Validation Engineer

Chapter 13 interview drill

Interview questions: Overfitting, leakage, augmentation, and baselines

Practise a 60–90 second answer: define the idea, connect it to a physical robot, state assumptions, frames, and units when relevant, then finish with the failure signal or evidence you would inspect.

Primary interview scenario

A model reports 99 percent validation success after random frame splitting but fails when the table color changes. Diagnose leakage and shortcut learning, then define a credible reevaluation.

Answer shape: clarify the situation → trace the physical and software path → test the most likely boundaries → name the evidence that would confirm the result.

Technical follow-up questions

Q1What does a 0.25 train-validation MSE gap tell you?
Model interview answer

It shows worse held-out fit under comparable metrics, but further evidence is required to distinguish capacity, leakage, noise, duplicates, or distribution mismatch.

Q2Can augmentation make a leaked validation score valid?
Model interview answer

No; the contaminated split and every decision based on it must be repaired and reevaluated before augmentation effects are interpreted.

Q3Why keep a mean or linear baseline?
Model interview answer

It reveals whether learned complexity improves untouched performance enough to justify its data, compute, latency, and failure cost.