Neural Networks
Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6
15 cards in “6.6 Training neural nets” · whole deck
6.6 Training neural nets
- What three things does training a neural network require?A loss function (cross-entropy), an optimization algorithm (gradient descent), and a way to compute the gradient of the loss with respect to every parameter (error backpropagation).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 168
- What loss is used for a neural classifier?Cross-entropy: binary \(-[y\log\hat{y} + (1-y)\log(1-\hat{y})]\) with a sigmoid output; for \(K\) classes, \(-\log\hat{y}_c\) for the correct class \(c\), i.e. the negative log likelihood.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 168
- Why can’t we just use the logistic regression gradient for a deep network?It only gives correct updates for the last weight layer; the loss is computed at the end, but we need derivatives with respect to weights deep in early layers.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 170
- What is error backpropagation?The algorithm (Rumelhart et al., 1986) for computing gradients in deep networks; it is an instance of backward differentiation on computation graphs.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 170
- What is a computation graph?A representation of a mathematical computation broken down into separate operations, each a node, with edges carrying outputs to the next operations.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 170
- Run the forward pass of \(L(a, b, c) = c(a + 2b)\) at \(a = 3\), \(b = 1\), \(c = -2\).\(d = 2b = 2\), \(e = a + d = 5\), \(L = c \cdot e = -10\).
Black: forward values. Orange: gradients from the backward pass. - Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, pp. 170–171
- What is the intuition of backward differentiation?Pass gradients back from the final node: each node multiplies the upstream gradient it receives by its local gradient (of its output with respect to each input) to get the downstream gradient for earlier nodes (chain rule).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 171
- Compute \(\partial L/\partial a\), \(\partial L/\partial b\), \(\partial L/\partial c\) for \(L = c(a + 2b)\) at \(a = 3, b = 1, c = -2\).\(\partial L/\partial c = e = 5\). \(\partial L/\partial e = c = -2\), so \(\partial L/\partial a = \frac{\partial L}{\partial e}\frac{\partial e}{\partial a} = -2 \cdot 1 = -2\) and \(\partial L/\partial b = \frac{\partial L}{\partial e}\frac{\partial e}{\partial d}\frac{\partial d}{\partial b} = -2 \cdot 1 \cdot 2 = -4\).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, pp. 171–172
- Why is the forward pass needed before the backward pass?It computes the intermediate values (like \(d\) and \(e\)) that the local derivatives depend on.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 172
- What are the derivatives of the sigmoid, tanh and ReLU?\(\sigma'(z) = \sigma(z)(1 - \sigma(z))\); \(\tanh'(z) = 1 - \tanh^2(z)\); ReLU’(z) = 0 for \(z < 0\), 1 for \(z \ge 0\) (undefined at 0, by convention 1).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, pp. 173–174
- For a sigmoid output with cross-entropy loss, what is \(\partial L/\partial z\) at the output?\(a^{[2]} - y\): \(\frac{\partial L}{\partial a}\frac{\partial a}{\partial z} = \big(-\frac{y}{a} + \frac{1-y}{1-a}\big)a(1-a) = a - y\).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 174
- How should neural network weights and inputs be initialized and prepared, compared with logistic regression?Network training is non-convex. Weights must be initialized with small random numbers (not 0, as in logistic regression), and inputs are normalized to zero mean and unit variance.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, pp. 174–175
- What is dropout?A regularization method: during training, at each update, each unit’s output is set to zero with probability \(p\) (and the rest renormalized), randomly dropping units and their connections.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 175
- Name typical neural network hyperparameters, and how they are set.Learning rate, mini-batch size, architecture (number of layers, hidden units per layer, activation functions), regularization (e.g. dropout rate), optimizer variant (e.g. Adam). They are tuned on a devset, not learned by gradient descent.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 175
- What role do frameworks like PyTorch and TensorFlow play?They build networks as computation graphs, making gradient computation and parallelization on GPUs easy.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 6, §6.6, p. 175
Source
- Daniel Jurafsky and James H. Martin. Speech and Language Processing. 3rd edition (draft). https://web.stanford.edu/~jurafsky/slp3/