liveBook · Manning

Optimization

As explained in Natural Language Processing in Action, Second Edition

An optimization algorithm is a procedure for selecting parameter values that improve an objective function.

Optimization selects model parameters that reduce a loss function. Picture the weights skiing down an error surface toward a low point, using gradients computed from training examples or mini-batches. section 5.3

Stochastic gradient descent (SGD) updates weights from one sample or a mini-batch rather than the entire dataset. Its learning rate controls step size: larger values may converge faster but can overshoot the minimum. Momentum accelerates movement in a promising direction and slows movement away from the target. section 5.2.5

A practical PyTorch optimization loop follows this sequence:

  • Tune hyperparameters such as learning rate and momentum for the problem rather than treating their initial values as universally effective. section 5.2.5

Optimizing a name classifier

A PyTorch logistic-regression network predicts whether names are associated with female labels. Binary cross-entropy supplies the loss, weighted by name frequencies; SGD receives the model parameters, a 0.02 learning rate, and 0.001 momentum. Across 200 epochs, the loop progressively lowers loss while test accuracy rises in the reported run.

For convolutional neural networks, optimization learns kernel weights instead of requiring hand-crafted text patterns. RMSprop improves gradient estimates by maintaining an exponentially decaying moving average of recent gradients, which can speed NLP CNN training. section 7.2.1 section 7.5.4

Figure 5.6 Convex error curve
figure

Use the convex error-curve figure to connect parameter choices with loss minima and the direction of optimization. section 5.3

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains loss surfaces, mini-batch gradients, learning rate, momentum, training loops, and RMSprop, stopping short of deeper optimizer derivations.
Examples
Demonstrates PyTorch SGD training for a weighted name-gender classifier and RMSprop selection for an NLP convolutional neural network.
What it assumes
Assumes familiarity with model weights and loss functions while building the gradient-update procedure through a concrete classification example.
What you can do after
Apply it via PyTorch by configuring an optimizer, running gradient updates, and monitoring training and test metrics.
How it connects
Connects loss functions, gradients, backpropagation, stochastic gradient descent, momentum, learning rate, RMSprop, and convolutional neural networks.

Also explained in

Compare how 30 books explain optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.