Neural tangent kernel: predict training from the initial Jacobian
神经切线核
Match a frozen-Jacobian model to kernel updates, then measure how a finite nonlinear network departs from it.
neural-tangent-kernelStart with the problem
Two training examples are coupled when changing the same parameter affects both predictions. The neural tangent kernel measures that coupling by taking inner products of parameter gradients. It turns a question about many parameter updates into a question about a matrix over examples.
Jacot, Gabriel and Hongler distinguish the finite network’s changing tangent kernel from an infinite-width limiting kernel. Lee and colleagues study training through a network’s first-order expansion around initialization. We will first verify the exact algebra for a frozen linearization, then compare it with a genuinely nonlinear two-hidden-unit network.
Definitions and derivation
For n scalar outputs and d trainable parameters, J is an n-by-d Jacobian. Its Gram matrix is the empirical tangent kernel:
Positive semidefiniteness follows immediately from the squared norm. It does not imply invertibility: repeated examples or dependent gradient features can give zero eigenvalues. In a finite nonlinear network J generally changes during training, so K changes too.
Freeze J at initialization θ₀ and approximate predictions by their first-order expansion. For half mean squared error, parameter-gradient descent on this linearized model is:
Multiply the parameter update by J₀ and add the unchanged f₀. The prediction residual obeys:
The step-size condition makes every positive-eigenvalue residual mode contract in magnitude. Zero-eigenvalue modes remain unchanged; interpolation requires that no target residual lies in those modes. This is a discrete-update statement for the frozen model. The exact nonlinear network instead follows a changing-kernel equation in continuous gradient flow, and finite discrete steps also incur higher-order Taylor error.
Our network is f(x)=[a₁tanh(w₁x+b₁)+a₂tanh(w₂x+b₂)]/√2. Derivatives with respect to a are hidden activations divided by √2; derivatives with respect to w are a(1−h²)x/√2; derivatives with respect to b omit x. All six parameters train. The kernel therefore includes more than just the final-layer features.
Run the calculation
The complete Python 3.12 / NumPy 1.26.4 program starts from six explicitly listed parameters and three input-target pairs. It runs three synchronized calculations for 20 steps: parameter updates in the linearized model, prediction-only kernel updates, and full nonlinear-network updates.
import numpy as np
def value_jacobian(theta, x):
theta, x = np.asarray(theta, dtype=float), np.asarray(x, dtype=float)
if theta.shape != (6,) or x.ndim != 1 or not 1 <= len(x) <= 16 or not np.isfinite(np.r_[theta, x]).all():
raise ValueError('Use six finite parameters and 1 to 16 scalar inputs.')
a, w, b = theta[:2], theta[2:4], theta[4:]
hidden = np.tanh(x[:, None] * w + b)
local = (1 - hidden ** 2) * a / np.sqrt(2)
value = hidden @ a / np.sqrt(2)
jac = np.column_stack((hidden / np.sqrt(2), local * x[:, None], local))
return value, jac
def initial():
return np.array([0.5, -0.8, 0.7, -1.0, 0.1, -0.2]), np.array([-1.0, 0.0, 1.0]), np.array([-1.0, 0.2, 1.0])
def train(steps=20, rate=0.2):
if type(steps) is not int or not 0 <= steps <= 200 or not np.isfinite(rate) or not 0 < rate <= 1:
raise ValueError('Use a bounded step count and positive learning rate at most 1.')
theta0, x, y = initial()
f0, j0 = value_jacobian(theta0, x)
kernel = j0 @ j0.T
delta, prediction, theta = np.zeros(6), f0.copy(), theta0.copy()
trace = []
for _ in range(steps):
linear = f0 + j0 @ delta
delta -= rate * j0.T @ (linear - y) / len(x)
prediction -= rate * kernel @ (prediction - y) / len(x)
nonlinear, jac = value_jacobian(theta, x)
theta -= rate * jac.T @ (nonlinear - y) / len(x)
actual, current_jac = value_jacobian(theta, x)
trace.append((float(np.mean((prediction-y)**2)/2), float(np.mean((actual-y)**2)/2)))
actual, current_jac = value_jacobian(theta, x)
return f0 + j0 @ delta, prediction, actual, kernel, current_jac @ current_jac.T, trace
if __name__ == '__main__':
linear, kernel_prediction, nonlinear, k0, kt, trace = train()
print('initial kernel eigenvalues', np.linalg.eigvalsh(k0).round(9).tolist())
print('linearized / kernel discrepancy', float(np.max(np.abs(linear - kernel_prediction))))
print('linearized predictions', linear.round(9).tolist(), 'nonlinear predictions', nonlinear.round(9).tolist())
print('20-step losses: linearized / nonlinear', [round(v, 9) for v in trace[-1]])
print('kernel relative drift', round(float(np.linalg.norm(kt-k0)/np.linalg.norm(k0)), 9))
Actual output:
initial kernel eigenvalues [0.010755271, 0.664473324, 1.164237306]
linearized / kernel discrepancy 1.1102230246251565e-16
linearized predictions [-0.864613959, 0.160007383, 0.990971699] nonlinear predictions [-0.882898292, 0.154988882, 1.003859752]
20-step losses: linearized / nonlinear [0.00333505, 0.002625618]
kernel relative drift 0.370353272
The first two prediction vectors agree to floating-point precision. The nonlinear model differs and has a lower training loss in this example. The empirical kernel’s relative Frobenius drift is about 0.37035, so describing it as constant would be false. The initial kernel eigenvalues are positive, and η=0.2 satisfies the displayed stability condition. None of these observations estimates unseen-data performance.
Storing J costs O(nd), forming K densely costs O(n²d), and storing K costs O(n²). A kernel update costs O(n²); a parameter-space linearized update can instead multiply by J and Jᵀ without materializing K. Thus changing viewpoint can exchange dependence on parameter count for dependence on dataset size.
When the method fails
The infinite-width result requires the paper’s initialization, scaling and regularity conditions. Jacot’s training theorem assumes a Lipschitz, twice-differentiable activation with bounded second derivative and a stochastically bounded integrated training direction over the stated time interval. Width alone is not a license to assume every finite network has a fixed kernel.
Feature learning, substantial parameter movement, different parameterizations or optimizers can lead away from the frozen-kernel description. A positive-definite training Gram matrix concerns fitting the given samples, not generalization to a new distribution. Do not confuse the NTK with a covariance kernel of random network outputs: both can arise in wide-network analysis, but they are formed from different quantities.
Exercises with answers
- Why is K positive semidefinite?
Answer 1: For every vector v, vᵀKv equals ‖Jᵀv‖², which cannot be negative.
- What happens to a residual in the null space of K₀?
Answer 2: It is unchanged by the frozen-kernel recurrence, so the model cannot remove that component.
- Which two implementations should agree exactly in this example, up to rounding?
Answer 3: The frozen-Jacobian parameter update and its derived kernel prediction update.
- Does the measured 37% kernel drift support a constant-kernel description?
Answer 4: No. It is direct evidence that this finite nonlinear trajectory departs from the frozen kernel.
Sources and next steps
Jacot’s physical pages 4–6 define kernel dynamics, finite NTK and its stated limiting assumptions. Lee’s physical page 3, Equations 5–10, supplies the empirical Gram matrix and linearized-network viewpoint. The six-parameter model, discrete stability derivation and drift measurements are original. Compare Gaussian processes and kernel methods without identifying their distinct kernels automatically.
Make a prediction, then check
Which matrix must stay frozen for the displayed linearized recurrence?
Learning objectives
- Derive frozen-Jacobian prediction dynamics and spectral stability.
- Measure finite-network kernel drift without claiming an infinite-width limit.
Prerequisites & connections
Explore related knowledge →References
- Neural Tangent Kernel: Convergence and Generalization in Neural Networks — arXiv v1
Arthur Jacot; Franck Gabriel; Clément Hongler · 2018 - Wide Neural Networks of Any Depth Evolve as Linear Models Under Gradient Descent — arXiv v1
Jaehoon Lee; Lechao Xiao; Samuel S. Schoenholz; Yasaman Bahri; Jascha Sohl-Dickstein; Jeffrey Pennington · 2019
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.
- Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, runnable examples and matching bilingual equations, code and exercises. Not an independent human or second-agent review.
- Four focused CPython 3.12.4 tests passed per chapter, including independent derivatives, integrals, normal equations or exact/literal trajectory references as appropriate. All eight programs use NumPy 1.26.4. Tests include augmentation geometry, exact quadratic certificates, finite differences, spectral solutions, conditional risk decompositions and masked neural-network training. CPU teaching calculations, not framework or GPU benchmarks.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- Neural Tangent Kernel: Convergence and Generalization in Neural Networks — arXiv v1 · Physical pages 4–6: random linear parametrization, finite NTK definition, Theorems 1–2 and their activation/training-direction assumptions.
- Wide Neural Networks of Any Depth Evolve as Linear Models Under Gradient Descent — arXiv v1 · Physical page 3, Section 2.2 and Equations 5–10: empirical tangent kernel, initial Taylor expansion and linearized dynamics.
Related topics