← All notes

A loss cannot fix what the training data never shows

By · · 6 min read

Claim. In this experiment, a length-consistency term at two tested strengths did not materially improve errors on unseen corrupted images. A test-time repair using additional sequence information cut the error from 10 pixels to under 1; this is not an equal-information comparison of training and inference constraints.

When a model fails in a recognisable way, the natural reflex is to add a loss term that penalises that way of failing. If predicted shapes come out distorted, penalise distortion; if outputs that should be consistent aren't, penalise inconsistency. What I couldn't say was what such a term does when the training data never contains the failure, so I set up the smallest case I could think of and measured it.

Why the term might do nothing, on paper

Training updates depend on a term's derivatives on the sampled training inputs. A consistency term may change behaviour on unseen inputs through the model's inductive bias, but its value on clean training data does not establish robustness to an unseen corruption. The hypothesis here is narrower: improving length consistency on already-visible bars may not teach this network to locate a hidden endpoint. The experiment tests two weights; it does not prove that every regularizer or weight must fail.

A constraint applied at test time works differently. It leaves the trained model fixed and modifies its outputs using additional assumptions or observations. Even a correct length constraint need not identify the correct endpoint; the repair below also relies on a reliable direction and other frames in the sequence.

The experiment

A small convolutional network sees a 48×48 image of a bright bar, with noise, and predicts the positions of both ends. Bars vary in length from 12 to 26 pixels and in position and angle. Training images are always clean. I trained three versions, three seeds each, for 5,000 steps: the plain end-point loss, and the same loss plus a length-consistency term, the absolute difference between predicted and true bar length, at weights 0.1 and 0.5.

The test set is 100 sequences of 30 images. Within a sequence the bar keeps one length while it turns and drifts slowly, as a rigid object would. In 15% of the images, between 45% and 70% of the bar is covered from one end, so the visible part is much shorter than the bar. That never happens in training.

Predicted bar length, image by image, before and after the test-time repair — A re-run of one seed of the note's experiment. GPU training isn't bit-for-bit reproducible, so its numbers sit close to the table's rather than on them. Lengths are relative to the true length. (interactive figure)
TrainingFar-end error, cleanFar-end error, coveredPredicted length on covered imagesLength term, end of training
End points only0.19 px10.3 px46% of true0.34
Plus length term, weight 0.10.19 px10.3 px46%0.32
Plus length term, weight 0.50.22 px10.2 px47%0.33

On clean images every version finds the ends to within a quarter of a pixel. On covered images every version places the far end at the end of the visible part, about 10 pixels short, and reports a bar less than half as long as it is. The length term changed none of that. Its own value at the end of training was the same, about 0.33, at every weight: it reached its floor on the clean training data and had nothing more to do there. A five-fold increase in its weight bought nothing on the failure it was meant to address, and cost a little on clean images.

A constraint at test time

The fact the training term was trying to express is that a bar's length doesn't change within a sequence. At test time that can be used directly. For each sequence I took the median of the predicted lengths as a robust estimate of the true one. Any image whose predicted length fell below 80% of that median was treated as collapsed, and its far end was moved along the predicted direction to the median length.

Far-end error, coveredFar-end error, cleanCovered images repairedClean images touched
Before the constraint10.3 px0.19 px
After the constraint0.65 px0.19 px100%0.7%

The error on covered images fell from 10.3 pixels to 0.65. The repair caught every covered image and touched 0.7% of the clean ones, without changing their error. The median works because collapsed images are a minority in every sequence; the direction works because the visible part of the bar still points the right way.

Scope clarification, 2026-10-28: the predictor sees one image, while the repair estimates length from the full sequence, including other frames. The gain therefore cannot be attributed to hard constraints alone. A temporal predictor with the same information, an augmentation baseline, and a matched-information constraint ablation are still needed. The later study, a valid reconstruction can still be the wrong one, separates structural compliance from image agreement and reference accuracy. No original experiment values were changed in this clarification.

When this is the right tool

It depends on knowledge that is true about the world and that the model is not guaranteed to have learnt. Here, rigid bars keep their length. The repair only acts on a sharp drop below the sequence's typical length, so it leaves alone the ordinary variation it can't distinguish from noise. A rule that forced every image to the median length would also have "fixed" any real change in length, and for objects that do change length that would be wrong.

The training-side lesson is broader. Hendrycks and Dietterich (2019)1 showed how much image classifiers degrade under common corruptions absent from their training data. The usual remedy is to change the training distribution, by adding augmentations that resemble the corruption, so that the failure appears where a loss can see it. I didn't try that here, and it is the obvious next experiment: it attacks the cause, where the test-time constraint attacks the symptom.

What I would check before adding a loss term

These are the questions I would now ask first:

  • Does the failure appear in the training data at all? Inspect the term's gradients and test weight changes on the affected condition; a small training value alone does not answer whether it can help.
  • Is the failure measured on the data where it actually occurs? An in-distribution validation metric can't see an out-of-distribution failure.
  • Is there knowledge about the outputs, such as constancy, smoothness or physical limits, that holds at test time regardless of the input, and can be applied there?

A length term can only pull against errors it can see, which is the general point of a shape term cannot constrain what it is invariant to. The robust median the repair relies on is examined in cleaning noisy labels with a local median.

What I still don't know

My corruption was a single, clean kind of occlusion, and my constraint was tailored to it. Real failures are messier, and a test-time repair that is too eager could do more harm than the failure it fixes. I measured the repair's false-alarm rate only on clean images from the same distribution. I also haven't run the augmentation experiment, which I expect would close most of the gap inside the model. Comparing the two on the same failure would show how much of the fix belongs in training and how much at inference.

References

  1. Benchmarking Neural Network Robustness to Common Corruptions and Perturbations — Dan Hendrycks and Thomas Dietterich, ICLR 2019