Neural networks are well known to be over-parameterized and can often easily fit data with near-zero training loss with decent generalization performance on test dataset. Although all these parameters are initialized at random, the optimization process can consistently lead to similarly good outcomes. And this is true even when the number of model parameters exceeds the number of training data points.
Neural tangent kernel (NTK) (Jacot et al. 2018) is a kernel to explain the evolution of neural networks during training via gradient descent. It leads to great insights into why neural networks with enough width can consistently converge to a global minimum when trained to minimize an empirical loss. In the post, we will do a deep dive into the motivation and definition of NTK, as well as the proof of a deterministic convergence at different initializations of neural networks with infinite width by characterizing NTK in such a setting.
🤓 Different from my previous posts, this one mainly focuses on a small number of core papers, less on the breadth of the literature review in the field. There are many interesting works after NTK, with modification or expansion of the theory for understanding the learning dynamics of NNs, but they won’t be covered here. The goal is to show all the math behind NTK in a clear and easy-to-follow format, so the post is quite math-intensive. If you notice any mistakes, please let me know and I will be happy to correct them quickly. Thanks in advance!
Basics
This section contains reviews of several very basic concepts which are core to understanding of neural tangent kernel. Feel free to skip.
Vector-to-vector Derivative
Given an input vector x∈Rn (as a column vector) and a function f:Rn→Rm, the derivative of f with respective to x is a m×n matrix, also known as Jacobian matrix:
Throughout the post, I use integer subscript(s) to refer to a single entry out of a vector or matrix value; i.e. xi indicates the i-th value in the vector x and fi(.) is the i-th entry in the output of the function.
The gradient of a vector with respect to a vector is defined as ∇xf=J⊤∈Rn×m and this formation is also valid when m=1 (i.e., scalar output).
Differential Equations
Differential equations describe the relationship between one or multiple functions and their derivatives. There are two main types of differential equations.
(1) ODE (Ordinary differential equation) contains only an unknown function of one random variable. ODEs are the main form of differential equations used in this post. A general form of ODE looks like (x,y,dxdy,…,dxndny)=0.
(2) PDE (Partial differential equation) contains unknown multivariable functions and their partial derivatives.
Let’s review the simplest case of differential equations and its solution. Separation of variables (Fourier method) can be used when all the terms containing one variable can be moved to one side, while the other terms are all moved to the other side. For example,
Given a is a constant scalar:dxdyMove same variables to the same side:ydyPut integral on both sides:∫ydyln(y)Finallyy=ay=adx=∫adx=ax+C′=eax+C′=Ceax
Central Limit Theorem
Given a collection of i.i.d. random variables, x1,…,xN with mean μ and variance σ2, the Central Limit Theorem (CTL) states that the expectation would be Gaussian distributed when N becomes really large.
xˉ=N1i=1∑Nxi∼N(μ,nσ2)when N→∞
CTL can also apply to multidimensional vectors, and then instead of a single scale σ2 we need to compute the covariance matrix of random variable Σ.
Taylor Expansion
The Taylor expansion is to express a function as an infinite sum of components, each represented in terms of this function’s derivatives. The Tayler expansion of a function f(x) at x=a can be written as:
f(x)=f(a)+k=1∑∞k!1(x−a)k∇xkf(x)∣x=a
where ∇k denotes the k-th derivative.
The first-order Taylor expansion is often used as a linear approximation of the function value:
f(x)≈f(a)+(x−a)∇xf(x)∣x=a
Kernel & Kernel Methods
A kernel is essentially a similarity function between two data points, K:X×X→R. It describes how sensitive the prediction for one data sample is to the prediction for the other; or in other words, how similar two data points are. The kernel should be symmetric, K(x,x’)=K(x’,x).
Depending on the problem structure, some kernels can be decomposed into two feature maps, one corresponding to one data point, and the kernel value is an inner product of these two features: K(x,x’)=⟨φ(x),φ(x’)⟩.
Kernel methods are a type of non-parametric, instance-based machine learning algorithms. Assuming we have known all the labels of training samples {x(i),y(i)}, the label for a new input x is predicted by a weighted sum ∑iK(x(i),x)y(i).
Gaussian Processes
Gaussian process (GP) is a non-parametric method by modeling a multivariate Gaussian probability distribution over a collection of random variables. GP assumes a prior over functions and then updates the posterior over functions based on what data points are observed.
Given a collection of data points {x(1),…,x(N)}, GP assumes that they follow a jointly multivariate Gaussian distribution, defined by a mean μ(x) and a covariance matrix Σ(x). Each entry at location (i,j) in the covariance matrix Σ(x) is defined by a kernel Σi,j=K(x(i),x(j)), also known as a covariance function. The core idea is – if two data points are deemed similar by the kernel, the function outputs should be close, too. Making predictions with GP for unknown data points is equivalent to drawing samples from this distribution, via a conditional distribution of unknown data points given observed ones.
Check this post for a high-quality and highly visualization tutorial on what Gaussian Processes are.
Notation
Let us consider a fully-connected neural networks with parameter θ, f(.;θ):Rn0→RnL. Layers are indexed from 0 (input) to L (output), each containing n0,…,nL neurons, including the input of size n0 and the output of size nL. There are P=∑l=0L−1(nl+1)nl+1 parameters in total and thus we have θ∈RP.
The training dataset contains N data points, D={x(i),y(i)}i=1N. All the inputs are denoted as X={x(i)}i=1N and all the labels are denoted as Y={y(i)}i=1N.
Now let’s look into the forward pass computation in every layer in detail. For l=0,…,L−1, each layer l defines an affine transformation A(l) with a weight matrix w(l)∈Rnl×nl+1 and a bias term b(l)∈Rnl+1, as well as a pointwise nonlinearity function σ(.) which is Lipschitz continuous.
Note that the NTK parameterization applies a rescale weight $1/\sqrt{n_l}$ on the transformation to avoid divergence with infinite-width networks. The constant scalar β≥0 controls how much effort the bias terms have.
All the network parameters are initialized as an i.i.d Gaussian N(0,1) in the following analysis.
Neural Tangent Kernel
Neural tangent kernel (NTK) (Jacot et al. 2018) is an important concept for understanding neural network training via gradient descent. At its core, it explains how updating the model parameters on one data sample affects the predictions for other samples.
Let’s start with the intuition behind NTK, step by step.
The empirical loss function L:RP→R+ to minimize during training is defined as follows, using a per-sample cost function ℓ:Rn0×RnL→R+:
L(θ)=N1i=1∑Nℓ(f(x(i);θ),y(i))
and according to the chain rule. the gradient of the loss is:
When tracking how the network parameter θ evolves in time, each gradient descent update introduces a small incremental change of an infinitesimal step size. Because of the update step is small enough, it can be approximately viewed as a derivative on the time dimension:
dtdθ=−∇θL(θ)=−N1i=1∑N∇θf(x(i);θ)∇fℓ(f,y(i))
Again, by the chain rule, the network output evolves according to the derivative:
Here we find the Neural Tangent Kernel (NTK), as defined in the blue part in the above formula, K:Rn0×Rn0→RnL×nL :
K(x,x′;θ)=∇θf(x;θ)⊤∇θf(x′;θ)
where each entry in the output matrix at location (m,n),1≤m,n≤nL is:
Km,n(x,x′;θ)=p=1∑P∂θp∂fm(x;θ)∂θp∂fn(x′;θ)
The “feature map” form of one input x is φ(x)=∇θf(x;θ).
Infinite Width Networks
To understand why the effect of one gradient descent is so similar for different initializations of network parameters, several pioneering theoretical work starts with infinite width networks. We will look into detailed proof using NTK of how it guarantees that infinite width networks can converge to a global minimum when trained to minimize an empirical loss.
Connection with Gaussian Processes
Deep neural networks have deep connection with gaussian processes (Neal 1994). The output functions of a L-layer network, fi(x;θ) for i=1,…,nL , are i.i.d. centered Gaussian process of covariance Σ(L), defined recursively as:
Since the weights and biases are initialized i.i.d., all the output dimensions of this network A~1(1)(x),…,A~n1(1)(x) are also i.i.d. Given different inputs, the m-th network outputs A~m(1)(.) have a joint multivariate Gaussian distribution, equivalent to a Gaussian process with covariance function (We know that mean μw=μb=0 and variance σw2=σb2=1)
(2) Using induction, we first assume the proposition is true for L=l, a l-layer network, and thus A~m(l)(.) is a Gaussian process with covariance Σ(l) and {A~i(l)}i=1nl are i.i.d.
Then we need to prove the proposition is also true for L=l+1. We compute the outputs by:
Since {A~i(l)(x)}i=1nl are i.i.d., according to central limit theorem, when the hidden layer gets infinitely wide nl→∞, A~m(l+1)(x) is Gaussian distributed with variance β2+Var(A~i(l)(x)). Note that A~1(l+1)(x),…,A~nl+1(l+1)(x) are still i.i.d.
A~m(l+1)(.) is equivalent to a Gaussian process with covariance function:
Σ(l+1)(x,x′)=E[A~m(l+1)(x)A~m(l+1)(x′)]=nl1σ(A~i(l)(x))⊤σ(A~i(l)(x′))+β2;similar to how we get Σ(1)
When nl→∞, according to central limit theorem,
Σ(l+1)(x,x′)→Ef∼N(0,Λ(l))[σ(f(x))⊤σ(f(x′))]+β2
The form of Gaussian processes in the above process is referred to as the Neural Network Gaussian Process (NNGP) (Lee & Bahri et al. (2018)).
Deterministic Neural Tangent Kernel
Finally we are now prepared enough to look into the most critical proposition from the NTK paper:
When n1,…,nL→∞ (network with infinite width), the NTK converges to be:
(1) deterministic at initialization, meaning that the kernel is irrelevant to the initialization values and only determined by the model architecture; and
(2) stays constant during training.
The proof depends on mathematical induction as well:
(1) First of all, we always have K(0)=0. When L=1, we can get the representation of NTK directly. It is deterministic and does not depend on the network initialization. There is no hidden layer, so there is nothing to take on infinite width.
(2) Now when L=l, we assume that a l-layer network with P~ parameters in total, \tilde{\theta} = (\mathbf{w}^{(0)}, \dots, \mathbf{w}^{(l-1)}, \mathbf{b}^{(0)}, \dots, \mathbf{b}^{(l-1)}) \in \mathbb{R}^\tilde{P}, has a NTK converging to a deterministic limit when n1,…,nl−1→∞.
Next let’s check the case L=l+1. Compared to a l-layer network, a (l+1)-layer network has additional weight matrix w(l) and bias b(l) and thus the total parameters contain θ=(θ~,w(l),b(l)).
The output function of this (l+1)-layer network is:
f(x;θ)=A~(l+1)(x;θ)=nl1w(l)⊤σ(A~(l)(x))+βb(l)
And we know its derivative with respect to different sets of parameters; let denote A~(l)=A~(l)(x) for brevity in the following equation:
Later, Arora et al. (2019) provided a proof with a weaker limit, that does not require all the hidden layers to be infinitely wide, but only requires the minimum width to be sufficiently large.
Linearized Models
From the previous section, according to the derivative chain rule, we have known that the gradient update on the output of an infinite width network is as follows; For brevity, we omit the inputs in the following analysis:
dtdf(θ)=−η∇θf(θ)⊤∇θf(θ)∇fL=−η∇θf(θ)⊤∇θf(θ)∇fL=−ηK(θ)∇fL=−ηK∞∇fL; for infinite width network
To track the evolution of θ in time, let’s consider it as a function of time step t. With Taylor expansion, the network learning dynamics can be simplified as:
Such formation is commonly referred to as the linearized model, given θ(0), f(θ(0)), and ∇θf(θ(0)) are all constants. Assuming that the incremental time step t is extremely small and the parameter is updated by gradient descent:
θ(t)−θ(0)flin(θ(t))−f(θ(0))dtdf(θ(t))dtdf(θ(t))=−η∇θL(θ)=−η∇θf(θ)⊤∇fL=−η∇θf(θ(0))⊤∇θf(X;θ(0))∇fL=−ηK(θ(0))∇fL=−ηK∞∇fL; for infinite width network
Eventually we get the same learning dynamics, which implies that a neural network with infinite width can be considerably simplified as governed by the above linearized model (Lee & Xiao, et al. 2019).
In a simple case when the empirical loss is an MSE loss, ∇θL(θ)=f(X;θ)−Y, the dynamics of the network becomes a simple linear ODE and it can be solved in a closed form:
dtdf(θ)=dtdg(θ)=∫g(θ)dg(θ)=g(θ)−ηK∞(f(θ)−Y)−ηK∞g(θ)−η∫K∞dt=Ce−ηK∞t; let g(θ)=f(θ)−Y
People observe that when a neural network is heavily over-parameterized, the model is able to learn with the training loss quickly converging to zero but the network parameters hardly change. Lazy training refers to the phenomenon. In other words, when the loss L has a decent amount of reduction, the change in the differential of the network f (aka the Jacobian matrix) is still very small.
Let θ(0) be the initial network parameters and θ(T) be the final network parameters when the loss has been minimized to zero. The delta change in parameter space can be approximated with first-order Taylor expansion:
Chizat et al. (2019) showed the proof for a two-layer neural network that E[κ(θ0)]→0 (getting into the lazy regime) when the number of hidden neurons →∞. Also, recommend this post for more discussion on linearized models and lazy training.