Search

Search papers and lessons

Neural Tangent Kernel: Convergence and Generalization in Neural Networks

Arthur Jacot, Franck Gabriel, Clément Hongler · 2018

In the infinite-width limit, a neural network trained by gradient descent follows one fixed kernel, the neural tangent kernel, so training behaves like kernel regression.

On this page

  • Colour = topic mix
  • Linear algebra
  • Calculus
  • Discrete math
  • Probability
  • Neural network basics
  • Losses & regularization
  • ReadReady to readNot yet

TL;DR

Jacot, Gabriel and Hongler show that a very wide, fully connected neural network trained by plain gradient descent can be described by one fixed kernel, the neural tangent kernel (NTK). The kernel is built from the network's depth, its nonlinearity and the scale of its starting weights. Because it stays fixed during training, the network's training becomes a kernel regression, and the question of what the network predicts on new inputs becomes a question about that kernel.

Builds on: Feedforward Neural Network, Gradient Descent, Kernel Function, Jacobian Matrix, Mean Squared Error · Leads to: Early Stopping, Kernel Ridge Regression

Why it mattered

Before 2018 two facts sat side by side with no bridge between them. A wide network at the start of training is a random function that behaves like a Gaussian process, and kernel methods such as kernel ridge regression were well understood. Training a network, however, was studied as a hard non-convex problem in weight space, and the authors said the dynamics of deep networks was still open.

The paper built the bridge. It showed that gradient descent on a wide network is a gradient descent in function space with respect to a kernel that is fixed in the limit. That gave researchers a set of tools that already worked for kernels, such as eigen-decompositions of Gram matrices, to study convergence and generalization of deep networks. Later work used the same picture to ask when gradient descent reaches zero training error in very wide networks, and why such networks predict well on test data. Its experiments include a batch of MNIST digits, where each image is a vector of 784 pixel values.

History

In 1994 Radford Neal showed that a one-hidden-layer network with random weights tends to a Gaussian process as its hidden layer grows. Around 2017 and 2018, follow-up work extended this to deep networks, including Lee and co-authors, whose "deep networks as Gaussian processes" paper describes the infinite-width limit at initialization. Jacot, Gabriel and Hongler then asked what happens during training, and showed that the kernel that governs the start also governs the whole trajectory. The paper was published at NeurIPS in 2018. It caught on because it turned a hard question about training into a question about kernels that researchers already knew how to analyse.

The problem

A network with two hidden layers of width 10,000 has about a hundred million parameters, since each pair of adjacent layers contributes their product in weights. Call the network function fθf_\theta, where θ\theta collects all weights and biases. The training cost C(fθ)C(f_\theta) depends on θ\theta through a composition, and even when the cost CC is convex in the function itself, the composite cost is in general highly non-convex in θ\theta. This is why the usual proofs of convergence for gradient descent do not apply directly.

Two questions follow. First, what does gradient descent do to the function values, both on the training inputs and at new inputs? Second, why do such over-parametrized networks fit random labels and still generalize on real data? The paper answers both by changing the coordinate system: it studies fθf_\theta itself, in the space of functions, instead of θ\theta.

How it works

  1. Fix the network. Use layers 00 to LL, with widths n0,…,nLn_0, \ldots, n_L, a smooth nonlinearity σ\sigma, and weights and biases drawn independently from N(0,1)\mathcal{N}(0,1). The forward pass scales each weight matrix by 1/nℓ1/\sqrt{n_\ell} and adds a bias scaled by a constant β\beta (the worked examples below use β=0.1\beta = 0.1). These scalings are what make the infinite-width limit well behaved.

  2. A gradient step moves the output, and the size of the move depends on the pair of inputs. Changing parameter θp\theta_p by a small amount changes the output at input xx by about ∂θpfθ(x)\partial_{\theta_p} f_\theta(x) times that amount. Adding up over all parameters, the change at xx caused by a training signal at x′x' is governed by

    Θ(x,x′)=∑p∂θpfθ(x) ∂θpfθ(x′).\Theta(x,x') = \sum_p \partial_{\theta_p} f_\theta(x)\,\partial_{\theta_p} f_\theta(x').

    This is the NTK: a number for every pair of inputs. Tiny instance: take a network with no hidden layer, two inputs, n0=2n_0 = 2, and f(x)=(w1x1+w2x2)/2+0.1 bf(x) = (w_1 x_1 + w_2 x_2)/\sqrt{2} + 0.1\,b. The derivatives are xi/2x_i/\sqrt{2} for each weight and 0.10.1 for the bias, so Θ(x,x′)=(x1x1′+x2x2′)/2+0.01\Theta(x,x') = (x_1 x_1' + x_2 x_2')/2 + 0.01. For x=(1,0)x = (1,0) this gives Θ(x,x)=0.51\Theta(x,x) = 0.51. Check: 1/2+0.01=0.511/2 + 0.01 = 0.51.

  3. Make the network wide, and the kernel stops being random. The sum in step 2 has one term per parameter. In a wide layer there are many terms, each depending on a different random weight, and by the law of large numbers the sum settles to a fixed value. The NTK at initialization therefore converges to a deterministic kernel Θ∞\Theta_\infty. This limit depends only on the depth, the nonlinearity and the variance of the starting weights, not on which random weights were drawn.

  4. Compute the limit one layer at a time. A recursion gives Θ∞\Theta_\infty for any depth. Each new layer adds the covariance of the outputs of that layer and multiplies the previous kernel by a derivative term. For a one-layer network the limit is exactly the kernel from step 2, so Θ∞(x,x)=0.51\Theta_\infty(x,x) = 0.51 and Θ∞(x,x′)=0.01\Theta_\infty(x,x') = 0.01 for the two inputs above.

  5. The kernel does not move during training. The paper proves that, as widths grow, Θ(t)\Theta(t) stays equal to Θ∞\Theta_\infty for all times tt in a window [0,T][0,T], as long as the total size of the training push over that window stays bounded. For least-squares training this bound holds. So the kernel frozen at initialization describes the whole run.

  6. Training is kernel gradient descent. With a fixed kernel, the change in the function at any input xx is a weighted sum of the residuals at the training inputs, with weights given by the kernel. This is exactly the update of kernel regression trained by gradient flow. The network's function therefore moves along a straight, known path in function space.

  7. Solve for least squares. Write the residual on the training inputs as rtr_t. It decays along the eigen-directions of the Gram matrix of Θ∞\Theta_\infty at rates set by the eigenvalues. Directions with large eigenvalues are fit first. In the long run the network interpolates the training points, and between them it predicts the kernel interpolant, plus a leftover term that vanishes on the training data.

flowchart LR
  A["Random weights at initialization"] --> B["Network function f, a random function"]
  B --> C["Each step changes f at every input"]
  C --> D["Kernel Theta: how two inputs move together"]
  D --> E["Wide limit: Theta becomes fixed Theta-infinity"]
  E --> F["Training is kernel gradient descent on f"]

The rates in step 7 are easy to see. Take illustrative top eigenvalues λ1=0.0457\lambda_1 = 0.0457, λ2=0.00108\lambda_2 = 0.00108 and λ3=0.00078\lambda_3 = 0.00078, of the size a kernel on a batch of digits can have. These are not measured values from the paper. Each component of the residual along eigenvector ii shrinks like e−λite^{-\lambda_i t}:

0200400600800100000.20.40.60.81training time t (steps times learning rate)remaining fraction
  • lambda 1 = 0.0457
  • lambda 2 = 0.00108
  • lambda 3 = 0.00078
The large-eigenvalue direction is gone within a few dozen steps. The small-eigenvalue directions are still almost untouched after 1000 steps.

The math

Setup: the NTK and the training flow (step 2 in symbols)

Take a scalar output, so fθ(x)∈Rf_\theta(x)\in\mathbb{R}. Given training inputs x1,…,xNx_1, \ldots, x_N with targets y1,…,yNy_1, \ldots, y_N, the squared cost is

C(θ)=12∑j=1N(fθ(xj)−yj)2.C(\theta) = \frac{1}{2}\sum_{j=1}^{N}\bigl(f_\theta(x_j) - y_j\bigr)^2.

Gradient flow changes each parameter by θ˙p=−∂θpC\dot\theta_p = -\partial_{\theta_p} C. The chain rule gives the change of the function at any input xx:

∂tfθ(x)=∑p∂θpfθ(x) θ˙p=−∑j=1N(∑p∂θpfθ(x) ∂θpfθ(xj))(fθ(xj)−yj).\partial_t f_\theta(x) = \sum_p \partial_{\theta_p} f_\theta(x)\,\dot\theta_p = -\sum_{j=1}^{N}\Bigl(\sum_p \partial_{\theta_p} f_\theta(x)\,\partial_{\theta_p} f_\theta(x_j)\Bigr)\bigl(f_\theta(x_j) - y_j\bigr).

The bracketed sum is the NTK, so

∂tfθ(x)=−∑j=1NΘ(x,xj) (fθ(xj)−yj),Θ(x,x′)=∑p∂θpfθ(x) ∂θpfθ(x′).\partial_t f_\theta(x) = -\sum_{j=1}^{N} \Theta(x,x_j)\,\bigl(f_\theta(x_j) - y_j\bigr), \qquad \Theta(x,x') = \sum_p \partial_{\theta_p} f_\theta(x)\,\partial_{\theta_p} f_\theta(x').

The paper divides the cost by the number of data points, which only rescales time. The structure is the same.

Step 3 in symbols: the limiting kernel

Let Σ(1)(x,x′)=1n0 xTx′+β2\Sigma^{(1)}(x,x') = \frac{1}{n_0}\,x^{T}x' + \beta^2, and for each further layer

Σ(ℓ+1)(x,x′)=E[σ(u) σ(u′)]+β2,Σ˙(ℓ+1)(x,x′)=E[σ˙(u) σ˙(u′)].\Sigma^{(\ell+1)}(x,x') = \mathbb{E}\bigl[\sigma(u)\,\sigma(u')\bigr] + \beta^2, \qquad \dot\Sigma^{(\ell+1)}(x,x') = \mathbb{E}\bigl[\dot\sigma(u)\,\dot\sigma(u')\bigr].

Here (u,u′)(u, u') is a pair of values that are jointly Gaussian with covariance Σ(ℓ)\Sigma^{(\ell)} evaluated at (x,x′)(x, x'), and σ˙\dot\sigma is the derivative of σ\sigma. The limiting NTK is

Θ∞(1)=Σ(1),Θ∞(ℓ+1)(x,x′)=Θ∞(ℓ)(x,x′) Σ˙(ℓ+1)(x,x′)+Σ(ℓ+1)(x,x′).\Theta^{(1)}_\infty = \Sigma^{(1)}, \qquad \Theta^{(\ell+1)}_\infty(x,x') = \Theta^{(\ell)}_\infty(x,x')\,\dot\Sigma^{(\ell+1)}(x,x') + \Sigma^{(\ell+1)}(x,x').

The second summand is the learning done by the last layer. The first summand is the learning done by the layers below it. This matches the paper's remark that the two parts play different roles.

Step 4 in symbols: the frozen kernel

The paper's Theorem 2 says that the kernel stays close to Θ∞\Theta_\infty over a window [0,T][0,T] when the total size of the training push over that window stays bounded, where dtd_t is the training direction. For the least-squares cost, dtd_t is the residual, and its norm decreases during training, so the condition holds.

Step 5 in symbols: training with a fixed kernel and its solution (step 7 in words)

Let K~\tilde K be the N×NN \times N Gram matrix with entries K~ij=Θ∞(xi,xj)\tilde K_{ij} = \Theta_\infty(x_i, x_j), and let rtr_t be the vector of residuals rt(j)=ft(xj)−yjr_t(j) = f_t(x_j) - y_j. Integrating the flow from step 2 with the frozen kernel gives

r˙t=−K~ rt,sort=e−tK~ r0.\dot r_t = -\tilde K\, r_t, \qquad\text{so}\qquad r_t = e^{-t\tilde K}\, r_0.

If K~vi=μivi\tilde K v_i = \mu_i v_i with orthonormal eigenvectors viv_i, then the component of r0r_0 along viv_i is multiplied by e−μite^{-\mu_i t}. Large μi\mu_i means fast fitting.

If K~\tilde K is invertible, then ∫0∞rs ds=K~−1r0\int_0^\infty r_s\,ds = \tilde K^{-1} r_0. Integrating the function update over time gives the limit at any input xx, with κ(x)=(Θ∞(x,xj))j\kappa(x) = \bigl(\Theta_\infty(x,x_j)\bigr)_j:

f∞(x)=f0(x)−κ(x)TK~−1(f0(x⋅)−y)=κ(x)TK~−1y+(f0(x)−κ(x)TK~−1f0(x⋅)).f_\infty(x) = f_0(x) - \kappa(x)^{T}\tilde K^{-1}\bigl(f_0(x_\cdot) - y\bigr) = \kappa(x)^{T}\tilde K^{-1} y + \Bigl(f_0(x) - \kappa(x)^{T}\tilde K^{-1} f_0(x_\cdot)\Bigr).

The first term is the kernel interpolant of the targets. The second term is the leftover of the random initial function, and it vanishes on the training inputs. The paper shows that the first term is also the kernel ridge regression solution as the regularisation goes to zero.

Worked examples

Example
Example 1: the kernel of a one-layer network (tiny)

Use the network from step 2: n0=2n_0 = 2, β=0.1\beta = 0.1, f(x)=(w1x1+w2x2)/2+0.1 bf(x) = (w_1 x_1 + w_2 x_2)/\sqrt{2} + 0.1\,b.

  1. Write the derivatives. ∂f/∂wi=xi/2\partial f/\partial w_i = x_i/\sqrt{2} and ∂f/∂b=0.1\partial f/\partial b = 0.1.
  2. Form the NTK as the sum over parameters: Θ(x,x′)=12(x1x1′+x2x2′)+0.12\Theta(x,x') = \tfrac{1}{2}(x_1 x_1' + x_2 x_2') + 0.1^2.
  3. Take x=(1,0)x = (1,0) and x′=(0,1)x' = (0,1). The dot product is 00, so Θ=0+0.01=0.01\Theta = 0 + 0.01 = 0.01. The two inputs barely move each other.
  4. Take x=x′=(1,0)x = x' = (1,0). The dot product is 11, so Θ=1/2+0.01=0.51\Theta = 1/2 + 0.01 = 0.51.
  5. Check against the limit: Σ(1)(x,x)=12∥x∥2+β2=0.5+0.01=0.51\Sigma^{(1)}(x,x) = \tfrac{1}{2}\lVert x\rVert^2 + \beta^2 = 0.5 + 0.01 = 0.51. It agrees with step 4.
Example
Example 2: two training points and the kernel's eigenvalues (standard)

Suppose the frozen kernel on two training inputs has Gram matrix K~=(2112)\tilde K = \begin{pmatrix} 2 & 1 \\ 1 & 2\end{pmatrix}, and the starting residual is r0=(1,0)r_0 = (1, 0). We want r1r_1.

  1. Find the eigenvalues. Solving det⁡(K~−μI)=0\det(\tilde K - \mu I) = 0 gives (2−μ)2−1=0(2-\mu)^2 - 1 = 0, so μ=3\mu = 3 or μ=1\mu = 1.
  2. Find the eigenvectors. For μ=3\mu = 3, take v1=(1,1)/2v_1 = (1,1)/\sqrt{2}. For μ=1\mu = 1, take v2=(1,−1)/2v_2 = (1,-1)/\sqrt{2}.
  3. Expand the starting residual. r0=(1,0)=12(1,1)+12(1,−1)r_0 = (1,0) = \tfrac{1}{2}(1,1) + \tfrac{1}{2}(1,-1). In normalised form that is 12v1+12v2\tfrac{1}{\sqrt{2}}v_1 + \tfrac{1}{\sqrt{2}}v_2.
  4. Apply the decay. The v1v_1 part is multiplied by e−3te^{-3t} and the v2v_2 part by e−te^{-t}. At t=1t = 1 the factors are e−3=0.04979e^{-3} = 0.04979 and e−1=0.36788e^{-1} = 0.36788.
  5. Put the parts back together. r1=12e−3 (1,1)+12e−1 (1,−1)r_1 = \tfrac{1}{2}e^{-3}\,(1,1) + \tfrac{1}{2}e^{-1}\,(1,-1).
  6. Compute the two entries. The first entry is 12(0.04979)+12(0.36788)=0.20884\tfrac{1}{2}(0.04979) + \tfrac{1}{2}(0.36788) = 0.20884. The second is 12(0.04979)−12(0.36788)=−0.15905\tfrac{1}{2}(0.04979) - \tfrac{1}{2}(0.36788) = -0.15905. So r1≈(0.2088,−0.1590)r_1 \approx (0.2088, -0.1590).
  7. Interpret. The residual on the first point dropped from 11 to about 0.210.21, and the second point moved away from 00 to about −0.16-0.16. The fast direction (1,1)(1,1) has nearly died out; the slow direction (1,−1)(1,-1) is still doing most of the work. Since K~\tilde K is invertible, the residual reaches 00 as tt grows.
Example
Example 3: the paper's MNIST direction (realistic)

Take a batch of MNIST digits, each a vector of n0=784n_0 = 784 pixels, and a kernel whose top eigenvalues are the illustrative λ1=0.0457\lambda_1 = 0.0457 and λ2=0.00108\lambda_2 = 0.00108. Suppose the residual starts exactly along the second eigen-direction with size 0.50.5, so the first direction starts at zero.

  1. Write the residual along the second component. It starts at 0.50.5 and evolves as 0.5 e−λ2t0.5\,e^{-\lambda_2 t}.
  2. Pick a time. Run for T=1000T = 1000 steps at learning rate 1.01.0, so one step is one unit of tt.
  3. Compute the exponent. λ2×1000=1.08\lambda_2 \times 1000 = 1.08.
  4. Compute the exponential. e−1.08=0.3396e^{-1.08} = 0.3396.
  5. Multiply by the starting size. 0.5×0.3396=0.16980.5 \times 0.3396 = 0.1698.
  6. Interpret. After 1000 steps the component along the second principal direction has shrunk from 0.50.5 to about 0.170.17. A direction with λ1=0.0457\lambda_1 = 0.0457 would shrink by a factor of about e−45.7e^{-45.7} in the same time, which is zero for practical purposes. So the fast, large-eigenvalue directions are fitted first. This is the early-stopping picture.

Try it: how many steps at learning rate 1.01.0 until the second-component residual is 1 percent of its starting size, ignoring the first component?

Answer: we need e−λ2t=0.01e^{-\lambda_2 t} = 0.01, so t=ln⁡(100)/λ2=4.605/0.00108≈4263t = \ln(100)/\lambda_2 = 4.605/0.00108 \approx 4263 steps.

Results

The two theorems are the main results. Theorem 1 says that as the hidden widths grow, the NTK at initialization converges in probability to the deterministic kernel Θ∞\Theta_\infty. Theorem 2 says the kernel stays at Θ∞\Theta_\infty throughout training, for any training direction whose total size stays bounded. Proposition 2 says the restriction of Θ∞\Theta_\infty to the unit sphere is positive definite when the network has at least two layers and the nonlinearity is not a polynomial, which is what makes gradient descent converge to a global minimum in this setting.

The experiments check these claims at finite width, with small networks and small datasets.

  • Convergence of the NTK. Fully connected networks on low-dimensional inputs at several widths. The kernel changes during training at narrow widths and much less at wide ones.
  • Kernel regression. A few training points, with the network's outputs compared with the Gaussian limit given by the kernels. The match improves with width.
  • Convergence along a principal component. On a batch of MNIST digits, the kernel's top eigenvalues differ sharply, and wider networks follow the predicted trajectory along a secondary component more closely. The limits are important. The proofs take the widths to infinity one layer at a time. The positive-definiteness result is proved only on the sphere and only for at least two layers. The experiments are small: a two-dimensional toy dataset and a batch of 512 digits. At finite width the kernel drifts during training, so finite networks depart from the limit in ways the frozen-kernel theory does not describe.

Limits, common misreadings and tradeoffs

It is tempting to think the NTK is a property of a trained network. In fact, for a finite network it is random at initialization and changes during training. Only the infinite-width limit is fixed. The drift shrinks as the width grows, which is what the theory predicts.

It is tempting to think the kernel is learned from the data. In fact Θ∞\Theta_\infty depends only on the depth, the nonlinearity and the variance of the initial weights. The data enter only when the kernel is evaluated on the training and test inputs. The features do not adapt the way a learned representation does.

It is tempting to think that comparing convergence speed by number of steps is fair across widths. In fact multiplying the kernel by a constant is the same as multiplying the learning rate by that constant. So a network with a larger kernel scale fits faster at the same learning rate, and convergence speeds have to be compared with the kernel scale taken into account.

When to use the NTK picture: to reason about convergence, about where early stopping helps, and about what a very wide network predicts. When not to use it: for finite networks whose hidden features change a lot during training, since the frozen-kernel picture cannot describe that change. Alternatives include analyses of finite-width corrections and the Gaussian-process view, which describes only the function at initialization.

Reading guide

  • A network's output moves during gradient descent in a direction set by the NTK, a kernel built from the derivatives of the output with respect to the parameters.
  • As width grows, the NTK settles on a deterministic kernel Θ∞\Theta_\infty that depends only on depth, nonlinearity and initial weight scale, and it stays fixed during training.
  • So training is kernel gradient descent in function space, and residuals decay along the eigen-directions of the kernel, the largest first.
  • Consequence: early stopping favours the large-eigenvalue, smooth components, and the limiting network is the kernel interpolant.

Read next: kernel ridge regression, which the paper identifies with the limit of its solution as regularisation goes to zero, and Gaussian process regression, the source of the infinite-width picture at initialization.

Check yourself

QuestionRecall: what is the NTK built from, and what does it measure?Show answer
The NTK is the sum over all parameters of the product of the output's derivatives at two inputs, Θ(x,x′)=∑p∂θpf(x) ∂θpf(x′)\Theta(x,x') = \sum_p \partial_{\theta_p} f(x)\,\partial_{\theta_p} f(x'). It measures how strongly a training signal at one input moves the output at the other.
QuestionComputation: a one-layer network has n0=2n_0 = 2 and β=0.1\beta = 0.1. What is its NTK at x=(0,2)x = (0, 2) with itself?Show answer
The dot product is 0+4=40 + 4 = 4. Divide by n0=2n_0 = 2 to get 22, then add β2=0.01\beta^2 = 0.01. The answer is Θ(x,x)=2.01\Theta(x,x) = 2.01.
QuestionWhy: why are the 1/nℓ1/\sqrt{n_\ell} factors in the forward pass needed?Show answer
Without them, each layer's contribution to the sum defining the NTK grows with the layer's width, so the kernel would blow up as the network gets wider instead of settling to a finite limit. The factors keep the limit consistent.
QuestionApplied: a wide network is trained with a small number of steps and stopped early. Which part of the target does it fit first, the smooth large-eigenvalue part or the noisy small-eigenvalue part?Show answer
The large-eigenvalue part. Its residual component decays as e−μte^{-\mu t} with a large μ\mu, so it is gone after a few steps, while small-eigenvalue components, which correspond to the less smooth parts of the target, are still almost untouched. Stopping early therefore keeps the network close to the smooth fit.

Sources

Read the full paper

Arthur Jacot, Franck Gabriel, Clément Hongler, 2018. arXiv:1806.07572