Lecture 13 The Math and Interpretation of Neural Network Models

13.1 Neural Network Regression
Model for Regression: \(y = f_\mathbf{w}(\mathbf{x}) + \epsilon\), where \(\epsilon\sim \mathcal{N}(0, \sigma^2)\) and \(f_\mathbf{w}\) is a neural network with parameters \(\mathbf{w}\).
Training Objective: find \(\mathbf{w}\) to maximize the joint log-likelihood of our data. This is equivalent to minimizing the Mean Square Error, \[\min_{\mathbf{w}}\, \mathcal{L}(\mathbf{w}) = \frac{1}{N}\sum^N_{n=1} \left(y_n - f_\mathbf{w}(\mathbf{x}_n)\right)^2\]
Optimizing the Training Objective: For linear regression (when \(f_\mathbf{w}\) is a linear function), we computed the gradient of \(\mathcal{L}\) with respect to the model parameters \(\mathbf{w}\), set it equal to zero and solved for the optimal \(\mathbf{w}\) analytically. For logistic regression, we computed the gradient and used (stochastic) gradient descent to “solve for where the gradient is zero”.
Can we do the same when \(f_\mathbf{w}\) is a neural network?
13.1.1 Why It’s Hard to Differentiate a Neural Network
Computing the gradient for any parameter in a neural network requires us to use the chain rule:
\[\begin{align} \frac{\partial}{\partial t} g(h(t)) = g'(h(t))h'(t),\quad& \text{or}\quad\frac{\partial g}{\partial t} = \frac{\partial g}{\partial h} \frac{\partial h}{\partial t} \end{align}\]
This is because a neural network is just a big composition of functions.
Let’s try to differentiate the following neural network, with activation function \(h(t) = e^{-0.5 t^2}\) seen as a composition of functions by hand.
We will first give a name to each parameter or weight in the neural network, \(w_{ij}^l\), where the superscript \(l\) indicates the layer from which the weight originates and the subscript \(ij\) indicates that this is a weight on an edge going from the \(i\)-th node in the \(l\)-th layer to the \(j\)-th node in the \((l+1)\)-th layer.
We will denote the output of the \(i\)-th node in the \(l\)-th layer as \(a_i^l\). We will denote the input to the \(i\)-th node in the \(l\)-th layer (a linear combination of the outputs of nodes in the previous layer) as \(s_i^l\).
In the “Forwards” column, we show you how each quantity \(a_i^l\) and \(s_i^l\) is computed as a function of the quantities in the previous layer.
To compute each partial derivative \(\frac{\partial \mathcal{L}}{\partial w_{ij}^l}\), we start with the definition of the loss function \(\mathcal{L}\) in terms of \(a_0^3\), and then apply the chain-rule \[\frac{\partial \mathcal{L}}{\partial s_{0}^3} = \frac{\partial \mathcal{L}}{\partial a_{0}^3}\frac{\partial a_{0}^3}{\partial s_{0}^3}\] to get a partial derivative of the loss function with respect to a quantity further down the neural network graph.
By repeating the application of the chain-rule to each layer of the neural network, we eventually get all partial derivatives \(\frac{\partial \mathcal{L}}{\partial w_{ij}^l}\).

You see that differentiating even a tiny network is a very complex time-consuming process!
13.1.2 Differentiating Neural Networks: Backpropagation
Luckily, the process of differentiating a neural network by iteratively applying the chain-rule can be automated!
Training a neural network using the backpropagation algorithm, which automatically computes the gradient of a neural network, consists of the following phases:
- (Initialize) initialize the network parameters \(\mathbf{W}\)
- Repeat:
- (Forward Pass) compute all intermediate values \(s_{i}^l\) and \(a_{i}^l\) for the given covariates \(\mathbf{X}\)
- (Backward Pass) compute all the gradients \(\frac{\partial \mathcal{L}}{\partial w^l_{ij}}\)
- (Update Parameters) update each parameter by \(-\eta \frac{\partial \mathcal{L}}{\partial w^l_{ij}}\)
Backpropagation is a special instance of reverse mode automatic differentiation – a method of algorithmically computing exact gradients for functions defined by combinations of simple functions, by drawing graphical models of the composition of functions and then taking gradients by going forwards-backwards.
13.2 Interpreting Neural Networks
Linear models are easy to interpret. Once we’ve found the MLE of the model parameters, we can formulate scientific hypotheses about the relationship between the outcome \(Y\) and the covariates \(\mathbf{X}\):
\[\begin{align} \widehat{\text{income}} = 2 * \text{education (yr)} + 3.1 * \text{married} - 1.5 * \text{gaps in work history} \end{align}\]
What do the weights of a neural network tell you about the relationship between the covariates and the outcome?

We might be tempted to conclude that neural networks are uninterpretable due to their complexity. But just because we can’t understand neural networks by inspecting the value of the individual weights, it does not mean that we can’t understand them.
There is, in fact, a large and growing body of methods for interpreting deep models. For a survey of these methods, as well as examples of both the promises and the pitfalls of explaining neural networks, see Section 12.6.
13.3 Neural Network Models and Generalization
Like other complex models, neural networks have low bias but potentially high variance. Just as in the case of linear and polynomial models, we can prevent neural networks from overfitting by regularization or by ensembling a large number of models. Very wide (over-parameterized) networks, however, can behave in surprising ways. See Section 12.5 for a discussion of the bias-variance trade-off for neural networks.