A model makes a surprising prediction. You want to know why. The usual answers point to features, attention weights, or a saliency map. Those answers explain the input. They do not explain the training data.

Influence functions answer a different question: which training examples pushed the model toward this prediction, and by how much? The idea is old, borrowed from robust statistics, and newly relevant now that models are trained on millions of examples nobody has inspected one by one. Used carefully, it turns "the data made it do that" from a slogan into a ranked list you can actually check.

The leave-one-out question, without retraining

The gold standard is simple to state and painful to run. Remove one training point, retrain the model, and see how the prediction changes. Repeat for every point. That is leave-one-out retraining, and it is far too expensive for any real model.

Influence functions approximate that experiment with calculus. Instead of deleting a point, imagine upweighting it by a tiny amount, call it epsilon, and ask how the fitted parameters move. If the model is smooth enough, that small change tells you a lot about the full deletion, at the cost of one clever linear algebra computation rather than thousands of retrainings.

Start with empirical risk minimisation. Given training points z_1 to z_n and a loss L, the fitted parameters are

θ^=argθmin​n1​i=1∑n​L(zi​,θ)

Now upweight a single point z by epsilon. The perturbed solution is

θ^ϵ,z=argminθn1​i=1∑n​L(zi​,θ)+ϵL(z,θ)

The influence of z on the parameters is the rate of change of this solution as epsilon moves away from zero:

Iparams(z)=dϵdθ^ϵ,z​∣∣​ϵ=0=−Hθ^−1∇θ​L(z,θ^)

Here H is the Hessian of the average training loss at the fitted parameters, and the gradient is taken at the same point. The formula has a clear reading. A point matters when its gradient is large, meaning the model still finds it surprising or hard to fit, and when that gradient aligns with directions the Hessian does not strongly constrain. A point in a flat direction of the loss moves parameters a long way. A point in a sharply curved direction barely moves them, because the rest of the data holds the parameters in place.

Removing a point is approximately the opposite of upweighting it, with epsilon set to minus one over n. So the approximate parameter change from deleting z is

θ^−z−θ^≈−n1​Iparams(z)=n1​Hθ^−1​∇θ​L(z,θ^)

From there, the influence on any quantity you care about follows by the chain rule. For the loss on a test point z_test, the classic result is

Iloss(z,ztest)=−∇θ​L(ztest​,θ^)⊤Hθ^−1​∇θ​L(z,θ^)

A positive value means upweighting z increases the test loss, so z is harmful for that prediction. A negative value means z helps. Sorting training points by this score gives you the most helpful and most harmful examples for a single prediction, without retraining.

Why the Hessian inverse is the whole problem

Everything above is easy except one object: the inverse Hessian times a vector. For a model with p parameters, forming H costs p squared memory and inverting it costs p cubed time. That is impossible for a neural network, and unnecessary. Influence functions only ever need H inverse applied to one vector, the test gradient. That product can be estimated without ever forming H.

The standard route is to solve the linear system H s = v, where v is the test gradient, using conjugate gradients or a stochastic Neumann-series estimator. Both methods need only Hessian-vector products, and a Hessian-vector product can be computed with one extra backward pass through a gradient-vector dot product, at roughly the cost of a gradient evaluation. In practice you run an iterative solver, watch the residual fall, and stop when the influence ranking stops changing, not when the solver has converged to machine precision. Ranking is usually stable long before the exact inverse is found.

For a small model, such as logistic regression, you can compute the exact version directly, and it is worth doing once to build intuition. The code below fits a logistic regression, computes the Hessian, and scores every training point by its influence on one test prediction.

import numpy as np # X: (n, d) training features, y: (n,) labels in {0, 1} # x_test: (d,) test point, y_test: its label def sigmoid(t): return 1.0 / (1.0 + np.exp(-t)) def influence_scores(X, y, theta, x_test, y_test, lam=1e-3): p = sigmoid(X @ theta) # Hessian of logistic loss plus a small ridge term W = p * (1.0 - p) H = (X * W[:, None]).T @ X / len(y) + lam * np.eye(X.shape[1]) # Gradient of the test loss p_test = sigmoid(x_test @ theta) grad_test = (p_test - y_test) * x_test # Solve H s = grad_test once, then score every point by a dot product s = np.linalg.solve(H, grad_test) grads = (p - y)[:, None] * X # Negative sign: positive score means the point raises test loss return -(grads @ s) / len(y) scores = influence_scores(X, y, theta, x_test, y_test) most_harmful = np.argsort(-scores)[:5] most_helpful = np.argsort(scores)[:5] 

Two details in this sketch are worth copying into larger implementations. First, the ridge term keeps H invertible when features are collinear or the model separates the data. Second, the expensive step, solving for s, happens once per test point, and scoring all training points after that is a single matrix-vector product. That asymmetry is what makes influence functions practical: one solver run buys you a ranking over the whole training set.

What influence scores actually find

The most useful results are rarely the points with the largest loss. A high-loss point the model already struggles with may have a small gradient at convergence in a well regularised model, or its gradient may point in a direction the rest of the data overwhelms. Influence adds geometry to surprise.

In practice, the top harmful points for a misclassified test example often fall into a few recognisable groups:

  • Mislabeled examples that pull the boundary toward the wrong class.
  • Near-duplicates of the test point with the opposite label, which act like a small, confident voting bloc.
  • Outliers or artefacts, such as a watermark or a formatting quirk, that the model has learned as a shortcut.
  • Points from a shifted subpopulation, for example a different hospital, camera, or annotation guideline, that happen to resemble the test case.

That is why influence functions are a debugging tool first and an explanation tool second. When a model fails on one slice of data, ranking the training points by influence on those failures often points to a data problem you can fix, relabel, or downweight, rather than a model problem you need to redesign around. The same ranking supports data valuation, dataset cleaning, and targeted audits: instead of reviewing the whole dataset, review the points that actually moved the predictions you care about.

Limitations and common pitfalls

Influence functions come with assumptions, and ignoring them produces confident nonsense.

First, the derivation assumes the model is at a stationary point of a twice-differentiable, locally convex loss. Deep networks are none of those things globally. In practice the method still often works as a local approximation, especially near convergence with weight decay, but the scores are approximations, not exact leave-one-out effects. Validate them on a sample: actually retrain without the top few points for a handful of test cases and check that the predicted change matches the observed change in sign and rough size. If it does not, do not trust the full ranking.

Second, the Hessian for a deep network is singular or nearly singular, and its inverse is sensitive to damping. Adding a small ridge term, as in the code above, is not a cosmetic fix. It changes the answer, by shrinking influence along flat directions. Report the damping you used, and check that the top-ranked points do not change wildly when you vary it by an order of magnitude. If they do, your ranking is a property of the regularisation, not of the data.

Third, influence is a local, first-order idea. It approximates the effect of one point at a time. It does not capture groups: ten individually harmless points can jointly move a prediction, and removing a whole cluster can behave very differently from removing its members one by one. Group influence methods exist, but they are more expensive and less standard. Treat a single-point ranking as a starting point for investigation, not as a complete causal account.

Fourth, influence scores are not causal statements about the world. A training point can be influential because it carries a spurious correlation, because it is mislabeled, or because it is genuinely the best evidence for the correct answer. The score tells you where to look. The label, the source, and the surrounding examples tell you what to conclude.

Finally, cost still matters. A Hessian-vector solver per test point is cheap compared with retraining, but it is not free, and it grows with model size and with the number of test points you want to explain. For routine use, score a small set of important or failing predictions, not every prediction in a test set.

When to use them

Reach for influence functions when a specific prediction matters and retraining is out of reach: a single high-stakes error, a failure on a protected or safety-critical slice, a suspicious pattern in a handful of outputs, or an audit that asks which training data shaped a decision. They are less useful as a global summary, where aggregate tools such as feature importance or dataset statistics are cheaper and clearer, and they are the wrong tool when the question is about causality in the world rather than sensitivity to the training set.

The deeper point is about accountability. A model is not just its architecture and its weights. It is also the data that moved those weights into place. Influence functions give you a way to trace a prediction back to the examples that earned it, one ranked list at a time, and to fix the data when that list shows you something wrong.

Connect with me on LinkedIn: linkedin.com/in/umeshtharukaofficial