Don't Mock Machine Learning Models In Unit Tests
- Source
- eugeneyan.com
- Publisher
- Eugene Yan
- Author
- Eugene Yan
- Date

Context
A test can pass while software misinterprets a 's prediction. Eugene Yan's testing essay describes the problem: replacing a model with a fabricated output can hide mistakes in how the maps output positions to class meanings.
The essay recommends keeping fast tests for ordinary processing logic while reserving selected checks for the actual model. Randomly initialized models can test structural properties such as output dimensions, but learned behavior requires learned weights. Small real-model checks can therefore catch a different category of failure from a mock, without requiring every unit test to load a large model.
- Model — A computational system that uses learned patterns to produce an output from information supplied to it.
- Application — Software arranged so that a person can use it; in this course, the software around a model that accepts your request, prepares the context and shows the reply.
“In software, we typically mock dependencies like APIs; in ML, we want to test the actual model (sometimes).”
Eugene Yan
“Google’s T5 NLI model classifies factual consistency with class = 1 while Meta’s BART NLI model classifies it with class = 2!”
Eugene Yan
“Don't Mock Machine Learning Models In Unit Tests”
Eugene Yan





