Skip to content

Basic Parts of Deep Learning: Data, Model, Cost, Optimizer

Nearly all deep learning algorithms are built from four parts: a dataset, a cost function, an optimization procedure, and a model. Goodfellow, Bengio, and Courville put it this way in Section 5.10 of Deep Learning: "Nearly all deep learning algorithms can be described as particular instances of a fairly simple recipe: combine a specification of a dataset, a cost function, an optimization procedure and a model." The model is the function with adjustable parameters. The cost says what counts as doing badly. The optimizer is the rule that changes the parameters to lower the cost. The data is what the cost is measured on.

The authors add the useful consequence: "By realizing that we can replace any of these components mostly independently from the others, we can obtain a wide range of algorithms." Their own example is linear regression, which combines the data X and y, a negative log-likelihood cost, the model p(y | x) = N(y; wᵀx + b, 1), and an optimizer that solves for the point where the gradient of the cost is zero. Add a weight-decay term to the cost and you have a different algorithm. Make the model nonlinear and you usually need an iterative optimizer such as gradient descent.

Try it by hand. Keep the model ŷ = w·x and the data fixed: x = (1, 2, 3, 4) and y = (2, 4, 6, 40). The first three points lie exactly on y = 2x, and the fourth is an outlier. Choose a squared-error cost. Its minimum is w = Σxy / Σx² = (2 + 8 + 18 + 160) / (1 + 4 + 9 + 16) = 188/30 = 6.27, and the outlier drags the line up so that it misses every point. Now swap only the cost, to absolute error Σ|y − wx|. Checking candidate values of w, the minimum sits at w = 2, with a total absolute error of 32, all of it from the outlier, and it fits the other three points exactly. Compare the two answers on the squared-error cost: w = 6.27 scores 477.9 and w = 2 scores 1,024. So "lower training loss" depends on which loss you chose. By the squared measure w = 6.27 is better, and by the absolute measure w = 2 is, and only you can say which one matches what you actually want.

That is the lesson of the four parts. When a model misbehaves, ask which part to change. The data may be wrong, the model too weak, the cost may reward the wrong thing, or the optimizer may not be finding the minimum.

The trap: assuming that a lower training loss means the real-world goal is met. The loss is a stand-in you chose, and a stand-in can be minimized without reaching the goal. Data handling, regularization, and evaluation on unseen data remain essential, and these four parts are only the core of the recipe.

Prof Rod's rule: name all four parts for any model you use, and be ready to say which one you would change first.

The example data are invented, and the minima were found exactly.

Goodfellow, Bengio, and Courville, Deep Learning, MIT Press, 2016, Section 5.10 Building a Machine Learning Algorithm, p. 150