Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Reproducible AI experiments

Why your model gives a different answer every time, and what to pin

Eindhoven University of Technology

You run a training script twice and get two different accuracies. Nothing changed. This is the single most common reproducibility complaint with machine learning code, and it usually comes down to three sources of variation that are easy to control once you know where they are.

The problem, demonstrated

Here is an experiment with no seed set. Run this page twice and the numbers change.

[np.float64(-0.0885), np.float64(-0.0206), np.float64(-0.0493)]

Three runs, three answers. That is expected — but it means that if you report one number in a paper, nobody, including you, can get it back.

Source 1: the global random seed

The obvious fix is to seed the generator:

([np.float64(0.0193), np.float64(0.0708), np.float64(0.0058)], [np.float64(0.0193), np.float64(0.0708), np.float64(0.0058)])

Identical. But notice what actually happened: the sequence is reproducible, not each individual call. The three values within a run still differ from each other, because they consume the same stream in order. If you later insert another random call anywhere earlier in your script, every number after it shifts.

Source 2: generator state that isn’t global

The modern fix is an explicit generator you pass around, so each component draws from its own stream:

np.True_

Now adding a random call elsewhere in the program cannot perturb this one. For anything with more than one stochastic component — data splitting, augmentation, initialisation, dropout — give each its own seeded generator.

Source 3: everything that isn’t your code

Seeds do not control:

Report variation, not a point estimate

If your result changes across seeds, that spread is information about your method, not noise to be hidden. Run several seeds and report the distribution:

mean of run means : -0.0202
std  of run means :  0.0308
range             : [-0.0723,  0.0385]

A method that beats a baseline by less than its own seed-to-seed spread has not been shown to beat it.

Checklist

Before an experiment counts as reproducible: