Neural Tangent Kernel: Convergence and Generalization in Neural Networks
As a network gets wider, gradient descent moves its outputs through a kernel that stays fixed, so an infinitely wide network trains like kernel regression.
The paper defines the neural tangent kernel, the dot product of two inputs' parameter gradients, which sets how much a gradient step on one example changes the prediction on another. In the infinite-width limit this kernel is the same for every random initialization and does not change during training, so under a squared-error loss the network's outputs follow a linear equation that can be solved exactly.
Explaining the paperNeural Tangent Kernel: Convergence and Generalization in Neural NetworksA 2018 theory paper from EPFL and Imperial College: two theorems about networks whose hidden layers grow without bound, checked on points of a circle and on 512 MNIST digits.
Arthur Jacot, Franck Gabriel and Clément Hongler study fully connected networks trained by gradient descent and ask what the trained network computes, which the non-convex loss surface had kept out of reach. Their answer holds in a limit, every hidden layer infinitely wide, and in that limit it is exact. The page covers, in order:
- the tangent kernel: how one gradient step on one example moves predictions on every other input;
- kernel gradient descent, the paper's way of describing training in function space;
- the 1/√n parametrization and the two theorems: the kernel becomes deterministic, then stops moving;
- the least-squares solution, which fits the kernel's top principal components first;
- what a trained infinitely wide network converges to, and what the result leaves unexplained.
What happens to the function during training
A network with parameter vector computes a function . Gradient descent moves , but the quantity anyone cares about is the function: what the network outputs on a training example, and on inputs it has never seen. The map from to is highly nonlinear, so the loss as a function of has saddle points and many minima, and nothing guarantees that gradient descent finds a good one.
The same loss written as a function of is simple. Least squares on examples is a convex bowl in the numbers . The difficulty is that gradient descent cannot move those numbers directly; it can only move , and each parameter step drags the whole function along with it, on training inputs and test inputs alike, by amounts the neural tangent kernel measures.
Earlier work describes the network before training. Neal (1996) showed that a one-hidden-layer network with random weights becomes a Gaussian process as its width goes to infinity: its output at any finite set of inputs is jointly Gaussian, with a covariance (a kernel) determined by the architecture. Lee et al. and Matthews et al. extended this to deep networks in 2018. This paper asks what happens to that random function once gradient descent starts moving it.
How the tangent kernel works
Take one gradient step on one training example with loss . Write for the residual. The step changes each parameter by , where is the learning rate. To first order in , the output at any other input changes by the sum over parameters of (how much depends on ) times (how much moved):
where
is the neural tangent kernel: the dot product of the two inputs' gradient vectors, each of length , the number of parameters. (For networks with several outputs it is an matrix per pair of inputs; the paper writes it as a sum of tensor products . This page uses one output, as the paper's experiments do.) Read as how far the output at moves, per unit of learning rate and residual, when a step pushes the output at . A large positive value means the two inputs share parameters that both outputs depend on in the same direction; a negative value means a push at pulls down.
A linear model makes this exact. Take . The gradient with respect to the parameters is , so , the same for every . Start at , train on the single point , , with . The residual is , the step is , and the new function is . At it rose by 1.5, which is with . At it fell by 0.3, which is with .
For a network, (1) holds only to first order, and the kernel itself depends on : the gradients in (2) are evaluated at the current parameters, so every step changes them. Figure 1 runs this on a real network. Its inputs are points on the unit circle, , so a function of can be drawn as a curve over the angle . The network has two ReLU hidden layers of width and one output; at it has 10,501 parameters, at , 1,005,001. Watch the bottom panel, where the actual change in the function after one gradient step is drawn over the prediction of (1) computed from the network's own kernel.
At the default setting (width 100, training input at 46°, target 0.5 above the current output, step size chosen so that (1) predicts landing exactly on the target), the network's own kernel gives , the learning rate is , and the output at moves from 0.479 to 0.971 against a predicted 0.979. Across the circle the largest gap between the actual and predicted change is 5.3% of the largest predicted change. At width 10 the gap is 22%; at width 1000 it is 1.1%. Two things are visible. The change has the shape of the kernel column , a bump centred on the training input that decays with angular distance, so one example moves the network's output on nearby inputs most and on distant ones much less. And the first-order picture gets more accurate as the width grows, at a fixed step size. Pushing the step slider to 2 doubles the step and shows the second-order error growing with it.
Kernel gradient descent
Summing (1) over all training examples and letting the learning rate go to zero turns gradient descent into a differential equation in training time (with learning rate , step corresponds to ; the paper's experiments use , so counts steps). For a cost that depends on the function only through its values at the training inputs, write for times the derivative of the cost with respect to the output (for a cost that averages over the examples, this cancels the average's ). The paper shows the network function then evolves as
and calls the right-hand side, with any kernel in place of , the kernel gradient . For least squares, and , the residual. Equation (3) says the training signal lives only on the training inputs, and the kernel spreads it to every other input. Predictions on test inputs are therefore whatever the kernel carries over from the training residuals.
Along this flow the cost falls at a rate set by the kernel:
If the Gram matrix is positive definite, the right side is strictly negative until the cost gradient on the data is zero. A convex cost bounded below, such as least squares, then converges to its global minimum. The non-convexity in parameter space does not enter, provided the kernel stays positive definite while training runs. For a finite network the proviso is not automatic, because changes with as training runs.
Section 3.1 of the paper gives a model where the kernel does not change. Draw random functions whose covariance is a target kernel , and fit only their linear combination
(the random-features model of Rahimi and Recht, 2007). The gradient with respect to is , independent of , so the tangent kernel is for the whole of training. It is random, because the features are, but it is an average of independent terms, and by the law of large numbers it converges to as . Gradient descent on this model is kernel gradient descent with a kernel close to . The paper's main theorems say a deep network behaves like this model as its width grows, although its features are not fixed and its parameters enter nonlinearly.
The 1/√n parametrization
The paper uses layers numbered 0 (input) to (output) with widths , a nonlinearity applied entrywise, and writes each layer as
with and output . Every weight and bias is initialized from . The usual parametrization (LeCun initialization) instead draws weights with variance and omits the factor. The two give the same function at initialization and the same set of representable functions; they differ in the gradients. In (6), the derivative of the output with respect to a weight carries the factor , so a hidden layer with weights contributes a sum of terms each of size about to the kernel (2), which stays finite as the width grows. Under LeCun initialization the same layer's contribution grows in proportion to the width, so the kernel has no finite limit. The in the random-features model (5) has the same role.
The paper notes a side effect: the factors put into every weight's gradient but not into the biases', which reduces the weights' influence on training relative to the biases. The scalar scales the biases down to balance the two. The experiments use and learning rate 1.0, which the paper equates to a width-100 network in the usual parametrization trained at learning rate 0.01. At width 100 a weight enters the layer as . Its gradient carries one factor , and dividing the updated by applies a second, so the effective weight moves by times the step a usual-parametrization weight takes at the same learning rate.
Why the NTK stops changing as width grows
The paper's two theorems are statements about the kernel (2) of the network (6) as the hidden widths go to infinity. The first concerns initialization. Proposition 1 restates the Gaussian-process result in this parametrization: each output tends to a centred Gaussian process with covariance , built layer by layer,
The expectation is over a pair of jointly Gaussian numbers with the previous layer's covariance: wide layers sum many independent terms, so each pre-activation is Gaussian by the central limit theorem, and the next layer's covariance is the average of applied to those Gaussians. Theorem 1 says the NTK converges in probability to a deterministic kernel (times the identity across outputs), given by
with the derivative of the nonlinearity. Read (9) as an accounting of parameters. The term is the contribution of layer 's own weights and biases: the gradient of with respect to them is the previous activation, and the dot product of activations averages to the covariance. The term carries the contributions of all earlier layers through one more nonlinearity, scaled by how often both inputs pass through it together (). The limit depends only on the depth, the nonlinearity, and the initialization variance.
For ReLU both expectations have closed forms (the arc-cosine kernels of Cho and Saul, 2009). For a centred Gaussian pair with variances and correlation ,
Work it through for the paper's setting: , inputs on the unit circle (), , and , so . Layer 1: and . Each ReLU layer halves the variance () and has , so and ; then , ; then , . For an input at 90° the limit is 0.0927, and at 180°, 0.0644: pushing the output at up moves the output at the opposite point of the circle up by less than a quarter as much.
Theorem 2 is about training. The parameters move along a training direction in function space (for gradient descent, , minus the cost derivative from (3)); as long as stays bounded as the width grows, which least squares guarantees because the residual only shrinks, the NTK stays equal to uniformly on . The mechanism, in Remark 4: each individual activation in a hidden layer changes by an amount that shrinks with width, so the gradients in (2) barely change, yet the many small changes add up to an order-one change in the output, which is what lets the lower layers contribute to learning at all. With a fixed kernel, (3) becomes a linear equation in , and the network trains exactly as kernel gradient descent with .
Figure 2 re-runs the paper's first experiment: a depth-4 ReLU network, for and around the unit circle, ten random initializations per width, before and after 200 gradient steps at learning rate 1.0 on the target . Look at two things as the width grows: how far the ten t = 0 curves spread around the dashed limit, and how far the trained curves move away from them.
At initialization the ten kernels at angle 0 have a standard deviation of 0.170 at width 20, 0.095 at 100, 0.040 at 500 and 0.020 at 2000: every fourfold increase in width halves the spread, the rate of an average of independent terms. The mean is close to the limit 0.2825 at every width from 100 up. Training moves the kernel in the direction the paper calls inflation: the mean value at angle 0 rises from 0.21 to 1.21 at width 20, by 86% at width 100, 20% at 500 and 4.4% at 2000. Over the same 200 steps the full parameter vector moves by 14.9%, 3.2%, 0.69% and 0.17% of its length, roughly in proportion to , because the distance travelled stays about the same while the length of grows with the number of parameters. All four widths reach a similar training loss after 200 steps, 0.016 to 0.022.
Proposition 2 handles the positive definiteness that (4) needs. For a non-polynomial Lipschitz nonlinearity (one with bounded slope, such as ReLU or tanh) and depth , the limiting NTK restricted to the unit sphere is positive definite, so for distinct training inputs on the sphere the Gram matrix is invertible and least-squares training converges to zero training error. The paper motivates the sphere by high-dimensional data, where centred points tend to have nearly equal norms.
Least squares and early stopping
With the kernel fixed and the least-squares cost, (3) is a linear ordinary differential equation for the function. Define the operator by , so (3) reads . Its solution is a matrix exponential:
On the training inputs, is the Gram matrix divided by . Its eigenvectors are the kernel principal components of the data (kernel PCA, Schölkopf et al. 1998), and its eigenvalues are the variance each component captures. Split the initial error into a part that the kernel cannot see (zero on every training input) and one part along each component. Each component then decays at its own rate:
A component with eigenvalue loses a factor of its error every time units. Large-eigenvalue components are fit first, and the paper reads this as a reason for early stopping: stopping at a moderate fits the top components and leaves the small-eigenvalue ones, which for smooth kernels are the high-frequency, noise-like directions, mostly unfit.
Evenly spaced points on a circle make the components easy to name. The limiting NTK depends only on the angle between two inputs, so with evenly spaced points the Gram matrix is circulant (each row is the previous row shifted by one), and its eigenvectors are the sines and cosines of frequency sampled at the 16 points. For the depth-4 limit with , the eigenvalues of are 0.124 for the constant (), 0.0440 for , 0.0183 for , 0.00653 for , falling to 0.00158 at . At learning rate 1, an error at frequency 1 loses a factor every 23 steps; at frequency 8, every 633 steps.
Figure 3 runs (12) exactly for that kernel on a target with Gaussian label noise. It shows the mean network, starting from ; the random part of decays by the same formula and returns in the next section. Press play and watch the bars: frequencies 1 and 2 hold the signal, and by their residuals are down to 1% and 16% of their starting size, while bars 5 to 8, which hold only noise, still have 79% to 85% of theirs.
With the default noise level of 0.2, the test error against the clean target bottoms out at 0.0159 near , when training error is still 0.029. After that the slow bars, which hold mostly noise, get fit too: training error goes to zero and test error climbs to 0.0388 by , 2.4 times the best value. With no noise the test error keeps falling to 0.0001 and stopping early only costs accuracy. Raising the noise to 0.5 moves the best stopping time earlier, to for the first noise draw.
The paper tests (13) on real data. It takes 512 MNIST digits, approximates the limiting kernel with a width-10,000 network, and finds the top three eigenvalues 0.0457, 0.00108 and 0.00078. The first component is nearly the constant function, because the kernel PCA is not centred, which explains the factor of 42 between the first two eigenvalues; with instead of 0.1 that gap is about ten times larger, which the paper reports makes training harder. It then sets the target to the initial network plus half the second component, . In the limit the error decays as , halving every steps, along a straight line in function space. Networks of width 100, 1000 and 10,000 deviate from that line less as the width grows, and the narrower ones converge faster than the wider ones, which the paper attributes to the kernel inflation of Figure 2: multiplying the kernel by a factor has the same effect as multiplying the learning rate.
What a trained wide network converges to
Letting in (12) gives the trained network in closed form. Write for the Gram matrix on the training inputs, for the row of kernel values between a test input and the training inputs, for the targets and for the initial network's outputs on the training inputs. With a positive-definite Gram matrix,
The first term is kernel regression with the NTK: it finds weights for which the sum of kernel bumps hits every training target exactly, and predicts with that sum. It equals kernel ridge regression with the ridge penalty sent to zero, and the posterior mean of a Gaussian process with prior covariance conditioned on noise-free observations. The second term is the part of the random initial function that training never removes. It equals zero at every training input, because there picks out that input's own value and the bracket cancels, and it is nonzero in between. Since is a Gaussian process at infinite width and (14) is linear in it, the trained network is Gaussian too, with mean given by the first term and a variance that vanishes on the training data.
Figure 4 re-runs the paper's second experiment: depth 4, four training points on the circle, 1000 steps at learning rate 1.0, ten networks each at widths 50 and 1000. The shaded band is the 10th to 90th percentile of the exact infinite-width Gaussian; its variance follows Lee et al. (2019, eq. 16), with as the covariance of .
Before training, the networks are random functions with a standard deviation of 0.285 at every input, the square root of . After training every network passes through all four points, where the band has zero width, and between the points the networks spread as the band predicts, at width 50 as well as at width 1000. The paper reports the same: even at width 50 the limit gives a good description of the distribution of trained networks. In our re-run the average of the ten networks differs from the limiting mean by 0.021 to 0.025 (root mean square over the circle), within the noise of averaging ten draws whose standard deviation is about 0.07.
The paper calls the first term of (14) the MAP (maximum a posteriori) estimate under a Gaussian prior with covariance . That describes the mean only. The random network the training started from has covariance , not , and Lee et al. (2019) show that the distribution of the trained network is the posterior of no probabilistic model, unless and happen to be proportional. Training only the last layer would give the posterior of the Gaussian process with kernel ; training all layers adds the lower-layer terms of (9) to the kernel without changing the prior.
What the NTK does not explain
Theorem 2 holds as the widths go to infinity and for a fixed training horizon . The proof in the appendix takes the widths to infinity one layer at a time, first , then , and assumes a twice-differentiable nonlinearity with bounded second derivative, while the experiments use ReLU (the paper notes the assumptions "do not seem to be strictly needed"). Yang (2019) proved convergence with the widths growing at equal rates, and Arora, Du, Hu, Li, Salakhutdinov and Wang (2019) gave a bound for ReLU networks that only needs every width to be large and covers infinite training time.
A constant kernel means the network's internal representations effectively do not change: the hidden activations move by amounts that vanish with width. Figure 2 shows the consequence at finite width, where the narrower networks' kernels moved by 20% to several hundred percent in 200 steps. Chizat, Oyallon and Bach (2019) named the frozen-kernel regime lazy training and showed that it comes from the choice of scaling: any model whose output is scaled up enough relative to its parameter changes trains this way. They also found that convolutional networks pushed into the lazy regime perform worse. The best convolutional NTK of Arora et al. (2019), an 11-layer architecture with global average pooling, reaches 77.43% on CIFAR-10, while the ResNet-110 of 2015 reached 93.57%. The μP explainer covers a parametrization chosen so that features keep changing as width grows, the alternative limit to this one.
Within its scope the NTK turns several observations about wide networks into theorems. Gradient descent on an over-parameterized network reaches zero training error despite the non-convex loss, because the kernel stays positive definite. Wide networks can fit any labels, including random ones as in the Rethinking Generalization experiments, because kernel regression with an invertible Gram matrix interpolates any targets; the paper's introduction makes the same comparison with kernel methods. And their predictions on new inputs are set by the kernel, so comparing limiting NTKs compares how architectures, depths and initializations generalize in this regime. The paper also notes that Theorem 2 allows training directions that come from another network, as in a GAN's generator update.
Computing the NTK
The limit (7)-(11) for ReLU takes a few lines. The listing computes and for one pair of inputs and reproduces the worked example above; the comment at the end gives the empirical kernel of a finite network, which Figure 1 computes layer by layer and an autograd library computes as a product of Jacobians.
import numpy as np
def relu_moments(a, b, c):
"""E[relu(u)relu(v)] and E[step(u)step(v)] for var a, b and cov c."""
s = np.sqrt(a * b)
th = np.arccos(np.clip(c / s, -1.0, 1.0))
e = s * (np.sin(th) + (np.pi - th) * np.cos(th)) / (2 * np.pi)
return e, (np.pi - th) / (2 * np.pi)
def ntk_limit(x, y, L, beta=0.1):
"""Sigma^(L) and Theta^(L)_inf for one pair of inputs (Prop. 1, Thm 1)."""
n0 = len(x)
S = x @ y / n0 + beta**2 # Sigma^(1)(x, y)
Sx = x @ x / n0 + beta**2 # Sigma^(1)(x, x)
Sy = y @ y / n0 + beta**2 # Sigma^(1)(y, y)
T = S # Theta^(1) = Sigma^(1)
for _ in range(L - 1):
e, edot = relu_moments(Sx, Sy, S)
Sx = relu_moments(Sx, Sx, Sx)[0] + beta**2
Sy = relu_moments(Sy, Sy, Sy)[0] + beta**2
S = e + beta**2 # Sigma^(l+1)
T = T * edot + S # Theta^(l+1) = Theta^(l) Sdot + Sigma
return S, T
x0 = np.array([1.0, 0.0])
print(ntk_limit(x0, x0, L=4)) # (0.08125, 0.2825)
# Empirical NTK of a finite net: sum over layers of
# (a_l(x) . a_l(y) / n_l + beta^2) * (delta_{l+1}(x) . delta_{l+1}(y))
# where a_l are activations and delta_{l+1} = df/dz_{l+1} from backprop.
# With autograd: theta = J(x) @ J(y).T, J = df/dparams (one row per input).For training inputs the limiting Gram matrix costs evaluations of this recursion, and (14) needs one solve, the usual cost of kernel regression: cheap for the 4 to 512 points of the paper's experiments. The solve takes on the order of operations, about for the 50,000 CIFAR-10 training images that Arora et al. used. The empirical NTK of a finite network costs a Jacobian of size , which for a 1,005,001-parameter network and 1,000 inputs is a billion numbers.
Questions you might still have
Does the NTK explain why deep learning works?
It explains one regime precisely: a network so wide, under the 1/sqrt(n) parametrization, that its tangent kernel does not move during training. In that regime the network is a kernel method with a kernel fixed by depth, nonlinearity and initialization, and it learns no new features. Networks trained in practice move their kernel substantially, and forcing them into the frozen-kernel regime makes them worse: the best infinite-width convolutional kernel of Arora et al. (2019) reaches 77.43% on CIFAR-10, where a 2015 ResNet-110 reached 93.57%. The NTK is a solvable baseline that real networks beat, and the μP explainer covers the parametrization that keeps features learning at large width.
How wide does a network have to be before the kernel stays fixed?
There is no single number; it depends on depth, learning rate, training length and the parametrization. In this page's re-run of the paper's first experiment, 200 steps at learning rate 1.0 raised the kernel value at the reference input by 86% at width 100, 20% at width 500 and 4.4% at width 2000. Arora et al. (2019) give a sufficient width that grows polynomially in depth and in one over the tolerance, far beyond practical sizes, but empirical agreement often starts much earlier, as the width-50 networks in Figure 4 show.
How is the NTK different from the Gaussian-process kernel of an infinitely wide network?
The Gaussian-process kernel Sigma is the covariance of the network's outputs at random initialization: it describes the prior over functions. The NTK Theta describes how the outputs move under gradient descent. Theta^(L) = Theta^(L-1) Sdot^(L) + Sigma^(L), so Sigma is the part of Theta contributed by the last layer's weights and biases; training only the last layer would give Sigma as the tangent kernel. Training all layers adds the lower-layer terms, which is why the trained network is not a Gaussian-process posterior with either kernel.
Why does the paper divide by sqrt(n) instead of using the usual initialization?
With weights of variance 1 and a 1/sqrt(n) factor in the forward pass, each parameter's gradient carries the same factor, so the sum over all parameters that defines the NTK converges to a finite limit as n grows. With standard (LeCun) initialization the forward pass at initialization is identical, but the gradients of a hidden layer's n^2 weights are not scaled down, and the NTK grows in proportion to the width. The set of functions the network can represent is the same in both parametrizations; only the training dynamics differ.
Does the result cover cross-entropy, or optimizers like Adam?
Theorem 2 covers any training rule of the form: each parameter moves by the inner product of its gradient with some direction d_t in function space, as long as the integral of the size of d_t up to time T stays bounded. Gradient descent on cross-entropy fits that form over a finite horizon; only least squares gives the closed-form solution (12) and (14). Adam rescales each parameter's step by its own running statistics, which is not of that form, so the paper's theorem does not apply to it.
Can I compute the NTK of my own network?
For a finite network, yes: the empirical NTK between two inputs is the dot product of the gradients of the output with respect to all parameters, J(x) J(x')^T. For N inputs that is an N by N Gram matrix built from an N by P Jacobian, which is expensive for large P but routine for small datasets. Google's Neural Tangents library computes empirical NTKs from JAX models and the infinite-width kernels in closed form for fully connected, convolutional and attention layers.
What does the NTK say about early stopping?
Under least squares, the error along each kernel principal component decays like exp(-lambda_i t). Components with large eigenvalues, which for the kernels in the paper are the smooth, low-frequency functions, are fit first; components with small eigenvalues, where label noise mostly lives, are fit last. Stopping early keeps the fitted large-eigenvalue part and leaves out the small-eigenvalue part. In Figure 3 with label noise 0.2, test error is lowest near t = 74 and 2.4 times higher once the noise is fully fit.
Why did the smaller networks converge faster in the paper's MNIST experiment?
The paper attributes it to kernel inflation. Finite networks' NTKs grow during training, more for narrower networks, and multiplying the kernel by a factor speeds up kernel gradient descent by the same factor, like raising the learning rate. The paper adds that wider networks have more stable kernels and could take larger learning rates, so comparing convergence by step count without accounting for the learning rate is misleading.
Footnotes & further reading
- The paper: Jacot, Gabriel & Hongler, Neural Tangent Kernel: Convergence and Generalization in Neural Networks (arXiv June 2018; NeurIPS 2018). The authors released no code.
- Infinite-width networks as Gaussian processes: Neal, Bayesian Learning for Neural Networks (1996); Lee et al., Deep Neural Networks as Gaussian Processes (ICLR 2018); Matthews et al., Gaussian Process Behaviour in Wide Deep Neural Networks (ICLR 2018). ReLU kernels: Cho & Saul, Kernel Methods for Deep Learning (NeurIPS 2009).
- Wide networks as linear models, and the distribution of the trained network: Lee et al., Wide Neural Networks of Any Depth Evolve as Linear Models Under Gradient Descent (NeurIPS 2019).
- Non-asymptotic convergence and the convolutional NTK: Arora, Du, Hu, Li, Salakhutdinov & Wang, On Exact Computation with an Infinitely Wide Neural Net (NeurIPS 2019). Equal-rate limits: Yang, Scaling Limits of Wide Neural Networks with Weight Sharing (2019).
- Lazy training: Chizat, Oyallon & Bach, On Lazy Training in Differentiable Programming (NeurIPS 2019). Feature-learning parametrizations: the μP (Tensor Programs V) and Spectral Condition for Feature Learning explainers.
- Random features: Rahimi & Recht, Random Features for Large-Scale Kernel Machines (NeurIPS 2007). Kernel PCA: Schölkopf, Smola & Müller, Nonlinear Component Analysis as a Kernel Eigenvalue Problem (Neural Computation, 1998). Software: Google's Neural Tangents library.
How could this explainer be improved? Found an error, or something unclear? I read every message.