Natural Language Processing · free preview

Gradient Descent on the Cross-Entropy Loss

The cross-entropy loss from conditional maximum likelihood, its clean gradient for logistic regression, and stochastic gradient descent in action.

1. Gradient Descent on the Cross-Entropy Loss

Gradient Descent on the Cross-Entropy Loss

2. Following the gradient downhill

Following the gradient downhill

3. Training a tiny sentiment classifier

Training a tiny sentiment classifier

4. One term of the cross-entropy loss

A classifier outputs y^=0.9\hat{y} = 0.9 and the gold label is y=0y = 0. Compute the cross-entropy loss LCE(y^,y)L_{\text{CE}}(\hat{y}, y) and round to three decimals.

5. The logistic gradient on one weight

During training, a document has feature value xj=5x_j = 5, the model outputs y^=0.7\hat{y} = 0.7, and the gold label is y=0y = 0. Compute ∂L∂wj=(y^−y) xj\frac{\partial L}{\partial w_j} = (\hat{y} - y)\,x_j and round to three decimals.

6. One SGD step

A weight starts at wj=1w_j = 1, the document's feature is xj=4x_j = 4, the model outputs y^=0.3\hat{y} = 0.3, the gold label is y=1y = 1, and the learning rate is η=0.1\eta = 0.1. After the SGD update wj←wj−η(y^−y)xjw_j \leftarrow w_j - \eta (\hat{y} - y) x_j, what is the new wjw_j? Round to three decimals.

7. Comparing gradient magnitudes

Both documents have the same feature value xj=3x_j = 3 and gold label y=0y = 0. Document A gets y^=0.1\hat{y} = 0.1 and document B gets y^=0.9\hat{y} = 0.9. Which weight update has the larger magnitude, and why?

8. Convexity, learning rates, and hyperparameters

Which statement about training logistic regression with gradient descent is correct?

Practice this interactively

Free account · instant grading · spaced review that schedules itself.

Start this course for free