A Recipe for Training Neural Networks
Open the sourceKarpathy teaches a cautious, staged process for training neural networks because their abstractions leak and failures often remain hidden. He recommends understanding the data first, validating a simple end-to-end pipeline, increasing capacity until the model can overfit, regularizing, tuning, and only then applying final performance improvements.
- Neural network training is not plug-and-play; practitioners need to understand the underlying technology and inspect how the system behaves. - Because misconfigured networks may continue training without exceptions, correctness must be established through reproducible experiments, baselines, visualizations, and explicit hypotheses. - Data should be inspected thoroughly before any neural network code is developed, with particular attention to patterns, biases, corruption, distributions, and outliers. - The initial training and evaluation pipeline should use a simple model and pass checks such as expected initial loss, single-batch overfitting, and dependency validation through gradients. - Model development should first minimize training error with sufficient capacity and then trade some training performance for better validation performance through regularization. - Complexity and hyperparameters should be introduced deliberately, one change at a time, before ensembles or extended training are used for final gains.
Based on Andrej Karpathy's public content. Not affiliated with or endorsed by Andrej Karpathy.
Supports these rules
Quotes from this video
“the data The first step to training a neural net is to not touch any neural net code at all and instead begin by thoroughly inspecting your”
“the outliers along any axis. The outliers especially almost always uncover some bugs in data quality or preprocessing.”
“In particular, it builds from simple to complex and at every step of the way we make concrete hypotheses about what will happen and then either validate them with an experiment or investigate until we find some issue.”
“What we try to prevent very hard is the introduction of a lot of “unverified” complexity at once, which is bound to introduce bugs/misconfigurations that will take forever to find (if ever).”
“**a “fast and furious” approach to training neural networks does not work**”
“The qualities that in my experience correlate most strongly to success in deep learning are patience and attention to detail.”
“**overfit one batch**. Overfit a single batch of only a few examples (e.g. as little as two).”
“If they do not, there is a bug somewhere and we cannot continue to the next stage.”
“**complexify only one at a time**.”
“Don’t throw the kitchen sink at your model at the start.”
“The stage is now set for iterating on a good model. The approach I like to take to finding a good model has two stages: first get a model large enough that it can overfit (i.e. focus on training loss) and then regularize it appropriately (give up some training loss to improve the validation loss).”
“Now it is time to regularize it and gain some validation accuracy by giving up some of the training accuracy.”