liveBook · Manning

Optimization

As explained in Deep Learning with Python, Third Edition

The procedure that updates model parameters based on the loss, typically by a variant of stochastic gradient descent.

Optimization updates a neural network’s weights so its predictions produce a lower loss. The loss supplies feedback: the optimizer uses it to move weights in a direction that improves the current examples. section 1.6 section 2.5

A practical training loop connects four pieces:

  • The model maps input data to predictions through layers containing weight tensors. section 2.5
  • The loss function compares predictions with targets and produces the quantity to minimize. section 1.6 section 3.6.4
  • Backpropagation computes the loss gradient with respect to the weights; gradient descent then moves the weights opposite the derivative. section 2.4.1 section 2.5
  • The optimizer selects the specific stochastic-gradient-descent rules, such as those used by Adam, RMSprop, or SGD with momentum. section 2.5 section 3.6.4

Configuring optimization with Keras

A Keras model can specify Adam during compilation, then train for five epochs with batches of 128 samples: model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]); model.fit(train_images, train_labels, epochs=5, batch_size=128). The loss is optimized, while accuracy is monitored rather than directly optimized. section 2.5 section 3.6.4

Figure 2.26 Relationship between the network, layers, loss function, and optimizer
deep learning in 3 figures 3 alt

Use the relationship diagram to connect layers and weights, the loss function, and the optimizer within training. section 2.5

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains loss feedback, derivatives, gradients, mini-batches, and named optimizers, while deferring custom training-loop implementation.
Examples
Uses MNIST classification with Keras, Adam, sparse categorical crossentropy, five epochs, and batches of 128 samples.
What it assumes
Assumes basic neural-network layers and loss functions, but builds derivative-based minimization from an intuitive local-slope explanation.
What you can do after
Operate/configure Keras training with built-in optimizers and learning-rate settings.
How it connects
Connects loss functions, backpropagation, derivatives, gradient descent, model weights, mini-batches, epochs, and training loops.

Also explained in

Compare how 30 books explain optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.