Let , where the inputs and the parameters are all scalars and is the natural log. What is the computational graph with intermediate nodes, and how do you use backpropagation on it to compute ?
Deep learning, Backpropagation
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can break a function into a graph of simple nodes, and run the backward pass node by node, multiplying the upstream gradient by each local gradient.
Key idea
A computational graph has one node per simple operation. In the backward pass, each node's gradient is (upstream gradient) (local gradient): the gradient arriving from later in the graph times the node's own derivative. Along the path , where , this gives .
Steps
- Forward pass and graph: break into one operation per node (, , , , , ), giving the two-branch graph (with into ) and (with into ) , joining at .
- Start the backward pass with . A bar means the gradient of with respect to that node, e.g. .
- Multiply node : its local gradient with respect to is , so (and ).
- Log node: . Add node: (and ). Multiply node : .
- Result: . The same pass also gives and for free.
- Sanity check with numbers : . This matches a finite difference of at (nudge slightly and see how much changes).
Common mistakes
- Differentiating directly in one line when the question asks for backpropagation on a graph. Show the nodes and local gradients, or you lose marks.
- Writing only the local gradient and forgetting to multiply by the upstream , or dropping the final factor .
- Treating as without the extra factor.
How long your answer should be
Half a page: the graph, the backward pass node by node and a numeric check; about 4 minutes.
Read this
Previous in Deep learning: A three-class classifier outputs the probability vector , and the true class is the second one. What is the cross-entropy loss?
Next in Deep learning: A convolutional layer takes a input and applies 16 filters of size with stride 1 and padding 2. What is the output shape, and how many learnable parameters does the layer have? What changes if the stride is 2 and the padding is 0?