betaFeedback

WorksComputer Science

Scalable AI Uncertainty Quantification via Generalized Laplace Active Subspaces

Abstract

Reliable uncertainty quantification (UQ) is essential for deploying neural networks in scientific and high-stakes applications, but full Bayesian inference over the network parameters is computationally infeasible. We propose a low-rank generalized Laplace approximation for neural-network UQ based on a small number of data-informed curvature directions. Starting from a generalized Bayesian posterior defined through an empirical loss, we construct a local Gaussian approximation around a pretrained set of weights in this active curvature subspace. The posterior variances in the retained subspace are available in closed form, and the prior variance is calibrated by an empirical Bayes procedure. The generalized Bayesian formulation allows us to compare two posterior scalings: the standard Bayesian scaling associated with the summed negative log likelihood, and a mean-loss scaling in which the empirical loss is normalized by the number of data. A central finding is that the standard scaling induces a data-size dependent contraction of the posterior variance in the leading active directions. In regression problems, this can force the low-rank framework to retain additional weak-curvature directions in order to achieve nominal coverage of calibration data. When posterior samples are propagated through the non-linear network, these additional directions can degrade the coherence of the predictive intervals and shift the posterior predictive mean away from the pretrained model. In contrast, the generalized mean-loss scaling yields a more stable, lower dimensional active subspace and produces calibrated, coherent predictive confidence intervals. These results indicate that generalized Laplace active subspaces provide a practical and scalable route to calibrated uncertainty quantification in neural networks.

Introduction

One of the biggest open questions concerning artificial intelligence (AI) is the reliability and trustworthiness of the predictions which emanate from its output. After training, AI software operating in inference mode can spew out predictions concerning the behaviour of a new system in the same class as those it has been trained on in virtually instantaneous fashion. Such predictions can have enormous value in many real world scenarios. In some situations, qualitative classifications suffice while others require only a modicum of accuracy to be beneficial; still others require accurate and precise predictions or they are not actionable. This last scenario is the one which is most often necessary in scientific and engineering contexts.

To use the results of a calculation inside a scientific procedure, one generally needs to know that the predictions are reliable within defined and suitably limited bounds of uncertainty. Actionable predictions must therefore not only be timely; they need to be of a sufficient level of accuracy and/or precision to be used with confidence. The problem with AI methods in general is that what they output often appears plausible and may pass muster as such for some applications; but in more quantitative scientific and mathematical domains, plausibility is not sufficient: we need to be clear about the level of certainty of its predictions. The key assessments of validation, verification and uncertainty quantification are regularly visited on physics-based models, e.g. for weather and climate prediction [1, 2], turbulence modelling [3, 4], tsunami hazards [5, 6] or biological applications [7]. In these instances there is an exactly defined mathematical model based on clearly defined equations that typically include a variety of parameters, whereas such systematic analysis are significantly more challenging for AI systems.

One immediately noticeable difference between AI and physics-based codes resides in the number of parameters which arise in the two cases. Whereas physics-based codes typically contain around five parameters [3], possibly several hundreds [8] (extending to a few thousand in some large scale codes), each parameter has a well-defined physical meaning pertaining to the underlying model. In AI software there are many orders of magnitude more, none of which has a physical interpretation, as they are simply free parameters. The impressive fitting of input-output data can be readily performed with so many free parameters in play, particularly when one works with held-out data sets. where all manner of optimisations can be conducted. The approach lends itself to the making of overconfident predictions, which can and often do unravel when the trained system is applied to data which it has not previously encountered. We are interested in the uncertainty of such predictions in terms of the uncertainty in the parameter values of the trained model; unlike a physics-based approach, lacking any physical meaning, these parameters cannot be meaningfully adjusted based on insights into the system which can be gleaned from mathematical models we have created.

The purpose of the present paper is to demonstrate that, despite the lack of clarity as to the meaning of the parameters in an AI system, it is possible to obtain predictive uncertainty estimates. A natural framework for quantifying parameter uncertainty is Bayesian inference [9]. In principle, one would place a prior distribution on the neural-network weights, update this prior by conditioning on data, and propagate the resulting posterior distribution through the network to obtain predictive uncertainty. In practice, since the parameter dimension is extremely large, standard sampling strategies are computationally infeasible. Scalable approximations are therefore unavoidable.

Scalable Bayesian neural-network posterior approximations include variational approaches such as Bayes by Backprop [10], which learns a parametric approximation to the posterior distribution over the network weights, typically using a Gaussian variational family. The resulting training objective is an evidence lower bound, consisting of an expected data-fit term and a Kullback–Leibler (KL) divergence to the prior. In practice, the balance between these two terms can be delicate, and may require specialized training strategies such as KL annealing or cyclical schedules [11].

By contrast, the Laplace approximation [12] is a post-hoc posterior approximation. It also models the parameter posterior by a Gaussian distribution, but this Gaussian is centred at a pre-trained set of weights, and its covariance is obtained from the local curvature of the log posterior density rather than by optimizing a variational distribution during training. While the posterior is now conceptually simple, the computational bottleneck shifts to the covariance matrix of the Laplace approximation, as it is too large to form explicitly for many networks. In this work we circumvent this bottleneck via a generalized-Bayes low-rank Laplace approximation. The posterior is restricted to a low-dimensional active subspace spanned by the dominant Gauss–Newton curvature directions of the empirical mean loss. These directions are computed using matrix-free curvature-vector products, so that the full covariance matrix is never formed. Although active subspaces are originally derived from the dominant directions of an uncentered covariance matrix of the gradient of a (physics-based) model [13], the overarching idea is similar, namely to find a linear projection to a low-dimensional subspace relevant for a quantity of interest. For the original active subspace approach this quantity was the model output subject to a prior distribution, in this work it is the posterior predictive uncertainty of a neural network. Within the subspace spanned by these dominant active directions, the posterior variances are available in closed form, while the prior variance is calibrated using a generalized-evidence criterion. The active subspace dimension is selected by empirical coverage on held-out calibration data, yielding predictive intervals that are both calibrated and sharp.

We derive our low-rank Laplace posterior within the framework of generalized Bayesian inference, where the data is connected to the parameters via a loss function, rather than a traditional likelihood function [14]. In particular we contrast summed with mean loss functions, where the latter is scaled by 1/N1/N, NN being the number of data records in the training set. The use of the summed loss equates to the standard Bayesian likelihood function. A central observation of the paper is that the scaling of the generalized posterior is not merely a technical detail. The standard Bayesian scaling leads to an increasingly concentrated posterior variance with the number of training data. To avoid such overconfident predictions, a low-rank approximation should then retain many weak-curvature directions with relatively high posterior variance. This increases the computational cost, and reduces the statistical coherence of the predictive output distribution. In other words, when samples from a local Gaussian weight posterior are propagated through the nonlinear network, these weak directions can shift the predictive mean or distort the resulting uncertainty intervals. Existing methods [15, 16] deal with this issue by replacing the full network with its linear expansion. By contrast, our generalized Bayesian mean-loss scaling avoids the purely data-size-driven contraction, results in a much lower-dimensional active subspace and can retain the full non-linear network. Numerical studies demonstrate that the proposed approach yields coherent predictive intervals with only a small number of active directions.

Results

Let f(x;θ)∈RMf(x;\theta) \in\mathbb{R}^{M} represent our Quantity of Interest (QoI), namely the output of a pretrained neural network. Here xx are the inputs to the neural network, whereas θ∈RD\theta\in\mathbb{R}^{D} is the collection of all connection weights. Furthermore, let (x,y)(x,y) denote all supervised training data, and specific independent identically-distributed training samples are indexed as (xn,yn)(x_n,y_n), n=1,⋯ ,Nn = 1,\cdots,N, with yn∈RMy_n \in\mathbb{R}^{M}. It is our goal to perform scalable uncertainty quantification of ff by propagating a low-rank Bayesian posterior distribution on θ\theta through the network.

Before we describe our results, we give a brief overview of our UQ framework, called generalized Laplace active subspaces. Full details are found in the Methods section; the PyTorch code and data to reproduce the results below are available through [17].

Generalized Laplace active subspaces

Two choices define our Bayesian posterior. First, instead of seeking a posterior distribution p(θ∣y)p(\theta\mid y) in the original DD-dimensional coordinate system of the connection weights, we seek a low-rank (d≪Dd \ll D) coordinate system that is most relevant for the posterior predictive uncertainty. Secondly, we do not employ the standard Bayesian belief update p(θ∣y)∝p(y∣θ)p(θ)p(\theta\mid y) \propto p(y \mid\theta)p(\theta), which uses the likelihood function p(y∣θ)p(y \mid\theta) to connect the parameters θ\theta to the observed data yy. For independent Gaussian observations, the corresponding negative log-likelihood is proportional to a summed loss. In contrast, neural networks are typically trained using an average loss LN\mathcal{L}_N, such as the mean squared error, which includes an additional factor 1/N1/N. To obtain a Bayesian-style update that is consistent with the average loss used in practice, we adopt the generalized Bayesian framework of [14] instead, which gives rise to the following posterior:

πβ(θ∣y)∝exp⁡[−βLN(θ)]p(θ),(1)\pi_\beta(\theta\mid y) \propto\exp[-\beta\mathcal{L}_N(\theta)]p(\theta), \tag*{(1)}

see § 4.1.1 for more details. The so-called ‘temperature’ parameter β\beta controls the contribution of the loss relative to the prior. This formulation includes the standard Bayesian posterior as a special case, obtained by the appropriate choice of β\beta, while also allowing alternative scalings such as the mean-loss scaling considered in this work. It therefore provides a convenient framework for studying how posterior scaling (i.e. the choice of β\beta) affects the dimension and structure of the resulting low-rank posterior approximation.

This posterior approximation is obtained by constructing a local Laplace approximation centered at the pre-trained weights θ0∈RD\theta_0 \in\mathbb{R}^D. With a commonly-assumed isotropic Gaussian prior p(θ)=N(0,σ02ID)p(\theta) = \mathcal{N}(0,\sigma_0^2 I_D), this results in a Gaussian posterior distribution πβ(θ∣y)=N(θ0,Σ)\pi_\beta(\theta\mid y) = \mathcal{N}(\theta_0,\Sigma), with

Σ=(βHL+1σ02ID)−1.(2)\Sigma= \left(\beta H_L + \frac{1}{\sigma_0^2}I_D\right)^{-1}. \tag*{(2)}

Here, HLH_L is defined to be the Hessian (curvature) of the mean loss: HL:=∇θ2LN(θ0)∈RD×DH_L := \nabla_\theta^2 \mathcal{L}_N(\theta_0) \in\mathbb{R}^{D \times D}. For large neural networks this matrix cannot be formed or inverted explicitly, and it may not be positive semi-definite. We therefore replace the full curvature by a low-rank approximation in the dominant eigenspace of the generalized Gauss-Newton matrix GG (defined by (28)), GG being a positive semi-definite approximation to HLH_L. The dd-dimensional dominant GG eigenspace with λ1≥λ2≥⋯≥λd\lambda_1 \ge\lambda_2 \ge\cdots\ge\lambda_d;

Gpj=λjpj,j=1,…,d,(3)Gp_j = \lambda_j p_j,\quad j = 1,\ldots,d, \tag*{(3)}

defines the projection matrix P=[p1,…,pd]∈RD×dP = [p_1,\ldots,p_d] \in\mathbb{R}^{D \times d}, used to obtain the posterior perturbations on top of θ0\theta_0 via

θ=θ0+Pz,z∈Rd.(4)\theta= \theta_0 + Pz,\quad z \in\mathbb{R}^d. \tag*{(4)}

In this way uncertainty is represented only via the dominant curvature-informed directions, along which the data was able to inform the parameters well. In the coordinate system of this subspace the Laplace posterior has diagonal covariance, with

σj2=1βλj+σ0−2.(5)\sigma_j^2 = \frac{1}{\beta\lambda_j + \sigma_0^{-2}}. \tag*{(5)}

Thus, once the leading eigenpairs (λj,pj)(\lambda_j,p_j) of GG are available, the posterior variances σj2\sigma_j^2 in the retained active directions are obtained in closed form. The eigenpairs are computed using automatic differentiation, matrix-free vector products GvGv and the Lanczos algorithm (see section 4.1.5). This avoids explicitly forming GG, and makes the construction applicable to networks with a large number of parameters. The resulting approximation is therefore both local and low-rank: local because it describes uncertainty around a single trained solution θ0\theta_0, and low-rank because only a small number of active directions are retained.

The prior variance σ02\sigma_0^2 sets the overall scale of the posterior, and can be calibrated by an empirical-Bayes criterion within the active subspace w0=PTθ0∈Rdw_0 = P^T\theta_0 \in\mathbb{R}^d. The resulting prior variance is found by solving

∥w0∥22=∑i=1d1α−1βλi+α=∑i=1dσ02−σi2,(6)\lVert w_0\rVert_2^2 = \sum_{i=1}^{d} \frac{1}{\alpha} - \frac{1}{\beta\lambda_i+\alpha} = \sum_{i=1}^{d} \sigma_0^2 - \sigma_i^2, \tag*{(6)}

for α=σ0−2\alpha= \sigma_0^{-2}. Note that this relation chooses the prior scale such that the norm of the projected parameter vector is consistent with the amount of variance reduction induced by the data in the active subspace.

The posterior predictive distribution is then approximated by sampling (4) and propagating these samples through the neural network f(x;θ)f(x;\theta). This sampling strategy is denoted as sampled Laplace. However, the non-linear nature of the network may distort the UQ estimates. So-called linearized Laplace methods [15], which replace the full network with its linear expansion (see (45)), are a means to counteract this. We will contrast these two sampling methods below.

Regression with known observational noise

We start with the same scalar (M=1M = 1) regression function with Gaussian noise as in [18], namely;

y(x)=sin⁡(4πx)+sin⁡(7πx)+ϵ,ϵ∼N(0,σ2),x∈[0,1],(7)y(x) = \sin(4\pi x) + \sin(7\pi x) + \epsilon,\quad\epsilon\sim\mathcal{N}(0,\sigma^2),\quad x \in[0,1], \tag*{(7)}

using a known noise of σ=0.1\sigma= 0.1.

Implementation verification. This example is used to verify the implementation, in particular the matrix-free computation of GvGv and the dominant eigenpairs of GG. We train a fully-connected feed-forward neural network, using back propagation with Stochastic Gradient Descent and the Adam optimizer [19, 20]. The learning rate was set at 0.001, and we used two hidden layers at 50 neurons each. The dimension of the weight space is D=2701D = 2701, small enough to explicitly form the full GG matrix (28). The matrix-free GvGv vector is contrasted against the corresponding explicit matrix-vector product in Figure 1. The absolute error ∣Gv−(Gv)explicit∣\lvert Gv-(Gv)_{\mathrm{explicit}}\rvert is O(10−8)O(10^{-8}) in general (using the torch.float32 data type). A similar verification for the matrix-free eigenpairs is displayed in Figure 2.

Matrix-vector product comparison

Figure 1. The matrix-vector product Gv∈RDGv \in\mathbb{R}^{D} with D=2701D = 2701, computed using the matrix-free method outlined in § 4.1.5, and by explicitly forming matrix GG via (28). The absolute error ∣Gv−(Gv)explicit∣\lvert Gv - (Gv)_{\mathrm{explicit}}\rvert is plotted on the right vertical axis.

Eigenvalue and eigenvector fits and errors

Figure 2. The dd leading eigenvalues λj\lambda_j and leading eigenvector p1\mathbf{p}_1 of GG, computed using the matrix-free method outlined in § 4.1.5, and by explicitly forming matrix GG via (28). The absolute errors are plotted on the right vertical axis.

Standard vs generalized scaling. Next we examine the scaling of the output confidence intervals (CIs) with the temperature parameter β\beta, with the CIs computed using the sampled Laplace strategy. As described in § 4.1.1, the value β=Nσ−2\beta= N\sigma^{-2} corresponds to the standard Bayesian setting, whereas with β=σ−2\beta= \sigma^{-2} we employ the generalized Bayesian scaling where the task of standard likelihood function is taken up by the mean-squared loss. For both posterior scalings we determine the active subspace dimension dd as described in § 4.1.7. Essentially, we increase d∈Nd \in\mathbb{N}, starting from d=1d = 1 and solve (6) for σ02\sigma_0^2 every iteration, until our computed 90% CIs achieve empirical coverage of (at least) 90% of held-out calibration data. Our goal here is to compare this minimal required subspace dimension dd for both posterior scalings.

Figure 3 displays the result. The generalized Bayesian posterior only required d=2d = 2 active subspace directions to achieve coverage, and produces coherent CIs. Conversely, the standard Bayesian scaling of β\beta required d=31d = 31 directions and yields slightly wider, less coherent intervals.

90% confidence intervals for generalized Bayesian scaling and standard Bayesian scaling

Figure 3. 90% confidence intervals for the, a) generalized Bayesian scaling, and b) standard Bayesian scaling. Both CIs were generated by drawing 1000 posterior samples, and propagating these through the network.

The preceding results were obtained with N=50N = 50 training data points. We now compare the standard and generalized scaling using N=1000N = 1000. The results from the generalized Bayesian scaling (not shown) are essentially unchanged by the increase in training data, as it still yields a 2D active subspace that generates consistent CIs. We therefore focus on the 90% CI results of the standard Bayesian scaling, as displayed in Figure 4. Clearly, the quality of the mean prediction and the CIs significantly degraded. Furthermore, instead of d=31d = 31, we now required 43 curvature directions to achieve coverage.

Results for the standard Bayesian scaling

Figure 4. The results for the standard Bayesian scaling β=Nσ−2\beta= N\sigma^{-2} with N=1000N = 1000 and d=43d = 43. The CIs were generated by drawing 1000 posterior samples, and propagating these through the network.

Sampled vs linear Laplace. The underfitted results of Figure 4 are a consequence of the of propagating the Laplace posterior through the non-linear network, see also [15]. Instead, the posterior predictive results obtained from linearized Laplace flinf_{\mathrm{lin}}, i.e. from (45), are shown in Figure 5 for N=100N = 100 and N=1000N = 1000 for the standard scaling. Due to the linearity of the predictive model, its distribution is Gaussian as well, with a standard deviation σf\sigma_f given by (46). We therefore perform the coverage calibration using a 95% confidence interval constructed from f(x;θ0)±2σff(x;\theta_0) \pm2\sigma_f, which avoids Monte Carlo sampling. We further imposed a maximum subspace dimension of dmax⁡=50d_{\max}=50.

Results for the standard Bayesian scaling with 75% and 40% coverage

Figure 5. The results for the standard Bayesian scaling β=Nσ−2\beta= N\sigma^{-2} combined with the linearized Laplace predictive posterior distribution, computed using f(x;θ0)±2σff(x;\theta_0) \pm2\sigma_f.

As expected, the posterior predictive mean is improved relative to Figure 4, since the linearized predictive distribution is centered by construction at the expansion-point prediction f(x;θ0)f(x;\theta_0). The confidence intervals are substantially narrower, confirming that the overly wide intervals observed for non-linear posterior sampling are largely caused by propagating weight samples through the non-linear network. However, the linearized predictive distribution is under resolved. For both N=100N=100 and N=1000N=1000, the calibration procedure reaches the maximum allowed dimension of 50, covering only approximately 75% and 40% of the calibration data, respectively, with nominal 95% confidence intervals.

Regression with unknown observational noise

The following test case involves the Concrete Compressive Strength dataset from the UCI machine learning repository, see [21] for details. This is a regression test case containing N=1030N = 1030 samples and 8 input features describing the concrete mixture, and a scalar output corresponding to compressive strength. We train the same architecture as the preceding test case, except that now it contains approximately D=106D = 10^{6} connection weights. This case therefore assesses the scalability of the proposed matrix-free low-rank generalized Laplace approximation.

Since the observation noise is unknown, we estimate the noise σ\sigma via residuals:

σ2≈1N∑n=1N∥yn−f(xn;θ0)∥22,\sigma^2 \approx\frac{1}{N}\sum_{n=1}^{N}\lVert y_n - f(x_n;\theta_0)\rVert_2^2,

which is approximately 0.07 for this test case, and we use this value to specify β\beta as before. We set the number of training data NN to be 90% of the 1030 available data points. The remainder (NcalN_{\mathrm{cal}}) is used to calibrate dd. We execute the calibration procedure until our target coverage of 90% is met, or until a preset maximum active subspace dimension dmax⁡=50d_{\max} = 50 is exceeded.

Standard vs generalized scaling. The coverage for both the generalized and standard Bayesian scaling is plotted versus dd in Figure 6(a). In the case of the former, the target coverage was reached at d=3d = 3, while for the latter it was never reached within the allotted range. In fact, even at d=50d = 50 only approximately 60% of the calibration data was covered by the 90% CIs.

Coverage of the calibration procedure for sampled and linear Laplace posterior prediction

Figure 6. (a) Sampled Laplace posterior prediction, 90% nominal coverage. (b) Linear Laplace posterior prediction, 95% nominal coverage. The coverage of the calibration procedure as outlined in § 4.1.7, versus the active subspace dimension dd, for both the standard Bayesian scaling β=Nσ−2\beta= N\sigma^{-2} and the generalized scaling β=σ−2\beta= \sigma^{-2}.

Sampled vs linear Laplace. The same coverage study was conducted with the linear predictive posterior distribution, using again a 95% confidence interval constructed from f(x;θ0)±2σff(x;\theta_0) \pm2\sigma_f. The overall results, see Figure 6(b), are similar compared to the sampled Laplace study. For the generalized scaling, with d=4d = 4 active dimensions the coverage criterion is met, while the coverage of the standard scaling stagnates.

Due to the multivariate input xx, we display the generalized Bayesian posterior predictive results in Figure 7(a) in the form of a parity plot. Here we show the mean predicted compressive strength versus itself with 90% sampled Laplace CIs, and the mean predicted compressive strength versus the calibration data. Visually speaking, for the generalized scaling the CIs are consistent, as the mean is generally centered around the validation data, and the 90% CIs encompass most data without being overly wide. The CIs generated by the standard scaling (Figure 7(b)) are indeed overconfident.

Parity plot of the mean compressive strength of concrete

Figure 7. (a) Generalized mean-loss scaling, d=3d = 3. (b) Standard Bayes scaling, d=50d = 50. The parity plot of the mean compressive strength of concrete, with 90% CIs. We show the standard and generalized scaling results, both computed with sampled Laplace.

Activity scores. The dominant eigenvectors of GG define important directions in parameter space. However, we can also extract information about the importance of individual connections weights. Activity scores, originally derived in [22], are (first-order) sensitivity indices for individual parameters, which can be extracted from the active subspace eigenmodes. Analogously, using the GG eigenmodes, we define the activity scores for individual connection weights as:

νi=∑j=1dλjpj,i2,i=1,…,D.(8)\nu_i = \sum_{j=1}^{d} \lambda_j p_{j,i}^{2}, \quad i = 1,\ldots,D. \tag*{(8)}

Here pj,ip_{j,i} is the ii-th component of the jj-th eigenvector of GG. The activity score νi\nu_i measures how strongly parameter coordinate ii contributes to the retained dd-dimensional curvature-informed active subspace, weighted by the importance λj\lambda_j of each active direction. Since the connection weights have no physical interpretation, we will use (8) primarily to examine if the contribution to the curvature is broadly distributed across the network, or concentrated in a small subset of connection weights. However, rather than plotting individual νi\nu_i, we first sort from largest to smallest and instead plot the cumulative scores

κi=∑j=1iνj∑j=1Dνj,i=1,⋯ ,D,(9)\kappa_i = \frac{\sum_{j=1}^{i} \nu_j}{\sum_{j=1}^{D} \nu_j}, \quad i = 1,\cdots,D, \tag*{(9)}

in a log-log plot. The results are shown in Figure 8. We see that the 1000 most-sensitive connection weights (just 0.1% of the total) rapidly saturate and are responsible for most of the curvature sensitivity. In particular, for this case the remaining 99.9% of weights account for 5% of the total sensitivity. This indicates that, in addition to being only d=3d = 3 dimensional, the active subspace is also localised in the high-dimensional weight space.

The cumulative (normalized) activity scores for our concrete compression strength feed-forward neural network with approximately $D = 10^{6}$ weights

Figure 8. The cumulative (normalized) activity scores for our concrete compression strength feed-forward neural network with approximately D=106D = 10^{6} weights.

Autoregressive classification for molecular generative modelling

For our final (classification) test case we consider the autoregressive molecular language model from [23]. Here, molecules are represented as simplified molecular-input line-entry specification (SMILES) strings, a sequence of characters corresponding to atoms, generated sequentially by a recurrent neural network trained to predict a discrete distribution for the next token. In particular, we use a 3-layer LSTM network part of the REINVENT toolkit ([24]) with 256 neurons per layer and approximately 1.6M weights, trained on SMILES strings from the ChEMBL database ([25]). The M=34M = 34 tokens that make up the SMILES vocabulary and some example ChEMBL molecules can be found in the Appendix. This makes molecular generation a sequence of autoregressive token-level classification problems since, at each step, the network outputs a softmax distribution over the vocabulary, from which the next token is sampled. We study here how the low-rank posterior uncertainty in the network (for both the standard and generalized scaling) affects free-running autoregressive molecular generation. This setting separates the intrinsic stochasticity of the softmax layer from epistemic variability induced by posterior weight perturbations.

Reducing computational cost via subsampling. The LSTM was trained on 1.25M SMILES strings, each containing a (varying) number of tokens, which results in a total number of data records of N=58.7MN = 58.7\mathrm{M}. As each GvGv product used in the Lanczos algorithm is an empirical average over the dataset (see (30)), we choose to randomly subsample the data for computational efficiency, computing the eigendecomposition of GG using NsubN_{\mathrm{sub}} SMILES strings instead. Note a similar strategy was employed by [16]. To examine the effect of this subsampling we plot the (absolute value of) the inner product between the dominant eigenvector p1p_1 and a reference vector p1refp_1^{\mathrm{ref}} as a function of NsubN_{\mathrm{sub}} in Figure 9. This reference vector was computed using Nsub=10kN_{\mathrm{sub}} = 10\mathrm{k}, and we replicate this procedure Nrep=5N_{\mathrm{rep}} = 5 times at each subsampling to account for sampling noise, creating 25 possible inner products per NsubN_{\mathrm{sub}}. While clear variation is present in the replica inner products for Nsub=500N_{\mathrm{sub}} = 500 and Nsub=1000N_{\mathrm{sub}} = 1000, ∣⟨p1,p1ref⟩∣\left|\langle p_1,p_1^{\mathrm{ref}}\rangle\right| soon clusters near 1, indicating that reasonable alignment with the reference eigenvector can be obtained with a small fraction of the total dataset. That said, we note that there is an obvious outlier for Nsub=3000N_{\mathrm{sub}} = 3000. This is most-likely caused by a p1p_1 which failed to converge during the Lanczos algorithm, such that all 5 corresponding ∣⟨p1,p1ref⟩∣\left|\langle p_1,p_1^{\mathrm{ref}}\rangle\right| cluster near 0.14 in this case. One simple way to flag such outliers for a given NsubN_{\mathrm{sub}} is computing the Nrep×NrepN_{\mathrm{rep}} \times N_{\mathrm{rep}} matrix with entries ∣⟨p1,i,p1,j⟩∣\left|\langle p_{1,i},p_{1,j}\rangle\right|, i,j=1,…,Nrepi,j = 1,\ldots,N_{\mathrm{rep}}, p1,ip_{1,i} being the i-th replica eigenvector. Ill-converged vectors will cause entries away from 1. All subsequent analysis was performed using Nsub=2000N_{\mathrm{sub}} = 2000 SMILES, corresponding to N=93kN = 93\mathrm{k} data points.

The inner products between the dominant eigenvector and the reference vector as a function of subsample size

Figure 9. The inner products ∣⟨p1,p1ref⟩∣\left|\langle p_1,p_1^{\mathrm{ref}}\rangle\right| as a function of Nsub∈{500,1000,1500,2000,2500,3000}N_{\mathrm{sub}} \in\{500, 1000, 1500, 2000, 2500, 3000\}, replicated 25 times per NsubN_{\mathrm{sub}}. The reference vectors p1refp_1^{\mathrm{ref}} were computed using Nsub=10.000N_{\mathrm{sub}} = 10.000 SMILES strings.

Standard vs generalized scaling. Our first results concern the output validity, as not all generated molecules are guaranteed to be chemically correct compounds.

REINVENT verifies the validity in a post processing step using the RDKit [26]. Note that validity here means RDKit can parse the SMILES string into a molecular graph and the graph passes basic chemical sanitization checks. It does not imply druglikeness, synthetic accessibility, or chemical plausibility. Table 1 shows the number of valid molecules out of a set of 10k generated SMILES strings for the baseline REINVENT model (i.e. with softmax-only uncertainty and weights fixed at θ0\theta_0), and the perturbed model Laplace models with standard and generalized scaling. When varying the active-subspace dimension from 1 to 3, the standard scaling does not result in a notable change in validity compared to the baseline model. For the generalized scaling, validity notably drops.

baselineLaplace (std. scaling)Laplace (gen. scaling)
d=1d = 1869287096863
d=2d = 2869287535279
d=3d = 3869287324435

Table 1. Number of valid SMILES strings (out of 10k).

The following results were obtained using only valid SMILES strings. Figure 10 shows the kernel density estimates of the sequence length of the molecules (i.e. the number of tokens), computed from 10k generated SMILES strings. Once again only the generalized scaling shows a departure from the baseline results. Especially for d=3d = 3 the generator produces longer SMILES strings, with an increased probability that the maximum allowed sequence length of 256 is reached. Finally, we examine the effect of the Laplace active subspaces on the distribution of several Quantities of Interest (QoIs), described in Table 2. The corresponding distribution are found in Figure 11.

Kernel density estimates of the sequence length for the standard and generalized scaling

Figure 10. Kernel density estimates of the sequence length for the standard and generalized scaling with d∈{1,2,3}d \in\{1, 2, 3\}. The maximum allowed sequence length is 256.

Molecular weight distributions for standard scaling and generalized scaling

(a) Molecular weight distributions.

SA score distributions for standard scaling and generalized scaling

(b) SA score distributions.

SlogP distributions for standard scaling and generalized scaling

(c) SlogP distributions.

Figure 11. Kernel density estimates of the QoIs for the standard and generalized scaling with d∈{1,2,3}d \in\{1, 2, 3\}.

QuantityDescription
Molecular weightMolecular size based on atomic masses, large values indicate large molecules.
SA scoreSynthetic Accessibility score, higher values indicate more difficult synthesis.
SlogPEstimate of how fat-soluble a molecule is.

Table 2. Molecular quantities of interest used to compare generated SMILES distributions within REINVENT.

Activity scores. The cumulative activity scores κi\kappa_i are shown in Figure 12, using d=2d = 2. Note the curve saturates less quickly compared to the concrete compression

Cumulative normalized activity scores for the REINVENT LSTM

Figure 12. The cumulative (normalized) activity scores for the REINVENT LSTM with approximately 1.6M weights. Computed using d=2d = 2.

strength case. Still, the first 7.6% of the activity scores already account for 95% of the total sensitivity.

Discussion

We now discuss our findings and contrast our proposed method with related work.

Posterior scaling and active-subspace dimension

The results show that the scaling of the generalized posterior plays a central role in the quality and efficiency of our low-rank approximation. Under the standard Bayesian scaling, the leading active directions become increasingly contracted with the number of training data, as σj2=(βλj+σ0−2)−1\sigma_j^2 = \left(\beta\lambda_j + \sigma_0^{-2}\right)^{-1} with β=Nσ0−2\beta= N\sigma_0^{-2} or β=N\beta= N for regression or classification respectively. This forces coverage calibration to retain many weak-curvature directions.

Note that this does not mean the standard scaling is intrinsically defective, since posterior contraction with increasing data is an expected feature of the standard Bayesian update. The standard Bayesian scaling and generalized mean-loss scaling define do different posterior objects, and in our specific context of low-rank posterior UQ for overparameterized neural networks, the generalized scaling can provide a more effective posterior approximation.

To further discuss this behaviour, consider Figure 13. For the analytic regression function (7), we plot the posterior variances and the contraction ratio;

Four panels showing contraction ratio and posterior variances for generalized and standard Bayesian scaling, with panels (a) $\beta=\sigma^{-2}$, $N=50$; (b) $\beta=N\sigma^{-2}$, $N=50$; (c) $\beta=\sigma^{-2}$, $N=1000$; and (d) $\beta=N\sigma^{-2}$, $N=1000$

Figure 13. The contraction ratio (10) and posterior variances (22) for the generalized (left column) and standard (right column) Bayesian scaling, for both N=50N = 50 and N=1000N = 1000. These results were computed using the analytic regression function (7).

ci:=σ02−σi2σ02=βλiβλi+1σ02,(10)c_i := \frac{\sigma_0^2-\sigma_i^2}{\sigma_0^2} = \frac{\beta\lambda_i}{\beta\lambda_i+\frac{1}{\sigma_0^2}}, \tag*{(10)}

for which ci≈1c_i \approx1 implies that the ii-th direction is strongly data-informed (since then σi2→0\sigma_i^2 \to0), and values close to zero denote prior-dominated directions (σi2→σ02\sigma_i^2 \to\sigma_0^2). Under the standard Bayesian scaling (Figure 13(b)-Figure 13(d)), while the leading directions are almost fully contracted (posterior dominated), the posterior variances remain close to zero over much of the leading spectrum, due to the scaling with NN: σi2≈1/(Nσ−2λi)\sigma_i^2 \approx1/(N\sigma^{-2}\lambda_i) when ci≈1c_i \approx1. Coverage calibration therefore selects directions much deeper in the spectrum, where the posterior variances increase rapidly, as the σi2\sigma_i^2 span multiple orders of magnitude. Consequently, nominal coverage is obtained only after adding directions that introduce substantial parameter-space variability along weak-curvature modes. This effect becomes more pronounced with more training data; in Figure 13(d) the variance along the leading active directions is reduced by an order of magnitude compared to Figure 13(b). As a result, d=43d = 43 was required to meet the coverage criterion, which exacerbates the aforementioned problems of incorporating weak curvature modes with high variance. In the non-linear network, these larger perturbations may move samples outside the local region in which the Laplace approximation is accurate, resulting in wider and less stable predictive intervals, as shown in Figure 4. A better mean posterior prediction can be obtained with a lower dd, at the cost of overconfident CIs, or by utilizing the linear predictive distribution. Such overconfident CIs were also observed with the UCI concrete compressive strength network with standard scaling, where 50 curvature directions were insufficient to achieve coverage. The slow increase displayed in Figure 6 also suggests a significantly higher subspace dimension is required to achieve target coverage. Moreover, the retained eigenvalue spectrum spans several orders of magnitude, indicating that the additional directions correspond to genuinely low-curvature modes.

While the linear predictive distribution does remove the non-linear sampling artifacts when they occur, the excessive posterior contraction with NN induced by the standard Bayesian scaling is still present for linear Laplace. This is clear from Figure 5-Figure 7. In contrast, under the generalized Bayesian scaling, sufficient uncertainty is retained in the leading active directions, regardless of NN or the posterior predictive method, and desired coverage was obtained with only d=4d = 4 or less in all cases. Thus, the uncertainty is concentrated in a small number of coherent active directions rather than spread across many weak-curvature modes.

The increase in the selected active subspace dimension under the standard Bayesian scaling is also computationally consequential. Although N=1000N = 1000 is not large by modern machine-learning standards, the standard scaling already requires a substantially higher posterior rank to achieve the desired coverage compared to N=50N = 50, which is a problem that will escalate with larger NN. That said, as we showed in § 2.4, for large datasets one could subsample the data when computing the eigenmodes of GG. Still, computing these modes under the standard scaling will require a larger dd, and therefore more Lanczos iterations (see § 4.1.5). Thus, the standard Bayesian scaling not only shifts uncertainty into weaker-curvature directions, but also increases the computational cost of the low-rank posterior approximation compared to the generalized scaling. In contrast, the generalized Bayesian mean-loss scaling achieves calibrated and sharp confidence intervals with a much smaller active subspace. The proposed approach therefore provides a practical route to calibrated predictive uncertainty for regression-based neural networks.

Similarly, for our autoregressive classification case, the standard scaling resulted in distributions that do not deviate from the baseline REINVENT model in any notable fashion, see Figure 11. The low-rank Laplace perturbations with d=1,2d = 1, 2 appear to add meaningful variation to the generated molecular distribution while remaining broadly within the regime learned by the pretrained generator. In contrast, d=3d = 3 clearly crosses a stability boundary. The generator can start to produce some long (carbon-rich), formally valid yet chemically implausible molecules with extreme SlogP values. Lipinski’s Rule of Five [27] is a rule of thumb used in drug discovery to evaluate if a chemical compound has the right properties to make it an orally active drug in humans. One violating condition of this rule is an SlogP value greater than 5, which occurs at a significantly higher probability once d=3d = 3. This suggests that the addition of third active direction pushes the autoregressive dynamics outside the chemically meaningful region of the model.

Overall, under standard Bayesian scaling, the low-rank Laplace generator remains close to the pretrained baseline for all tested subspace dimensions. Valid-molecule QoI distributions and sequence lengths are not meaningfully affected, indicating that the posterior samples remain in a local generative regime. The reason behind this is the same as in the regression case, and again will be become even more pronounced with increasing (subsampled) data size. In contrast, under generalized scaling, increasing the active-subspace dimension produces progressively stronger deviations from the baseline. The most pronounced effect is in the sequence-length distribution, where a higher dd introduces a long right tail, suggesting that generalized posterior perturbations affect the learned stopping behaviour. The same scaling also broadens the QoI distributions, indicating increased chemical exploration at the cost of generative stability.

However, this was only a sensitivity study of the effect of posterior weight perturbations on free running molecule generation. Our pretrained REINVENT model is already reasonably calibrated at the token level, and we therefore did not expect the additional uncertainty of the Laplace posterior to improve the predictive distribution. That said, low-rank Laplace methods have also been proposed for fine-tuned large language models (LLMs). For instance, the low-rank adaptation (LoRA) method of [28] is a means to fine tune an LLM by introducing low-rank updates to selected weight matrices. This deterministic fine-tuning can make the model poorly calibrated, often overconfident. Laplace-LoRA, introduced by [29] places a Laplace posterior over the fine-tuned LoRA parameters to induce variability in the logits/predicted probabilities. The prior precision is tuned using gradient descent, maximizing the Laplace evidence, such that the posterior predictive distribution becomes better calibrated and achieves lower negative log likelihood. Extending our generalized-Bayes active-subspace Laplace approximation to fine-tuned language models is therefore a promising direction for future work. This would shift the role of the Laplace approximation from probing generative sensitivity, as in the present REINVENT experiments, toward correcting overconfidence in fine-tuned autoregressive models.

Finally, the activity scores from Figure 8 and Figure 12 show that the active subspace is concentrated in a very small subset of all connection weights, relative to the total weight space. However, the active subspace w=PTθw = P^{T}\theta itself provides an even more compact representation, as it is a linear combination of connection weights instead of a collection of individual weights. Similar observations have been made in physics-based models, see e.g. [8].

Related work

In recent years several contributions to the problem of uncertainty quantification for neural networks have been made, see [30] or [31] for survey articles. Here we discuss those most relevant to our work.

Our work is related to the subspace inference framework of [32], where Bayesian model averaging is performed within low-dimensional parameter subspaces constructed from random projections, SGD-trajectory PCA, or mode-connecting curves. In contrast, we construct the subspace from the dominant generalized Gauss–Newton curvature directions of the empirical mean loss. In [32] posterior tempering is also used as a calibration device, although here the temperature is a hyper parameter selected by cross-validation, rather than being fixed by the loss function used in generalized Bayes. Our curvature-based setting exposes the different scaling issue of increasingly contracted leading active directions with NN for the standard scaling. The generalized Bayesian mean-loss scaling avoids this purely data-size-driven contraction. A further distinction is that our generalized Laplace approximation yields a closed-form Gaussian posterior in the active subspace, avoiding Markov-Chain Monte Carlo sampling or variational optimization within the subspace.

Most closely related is the low-rank Laplace subspace construction of [16], whose authors derive an optimal low-dimensional subspace model for approximating the predictive output covariance of a full Laplace approximation and propose a scalable compute strategy. Their construction is formulated in the linearized Laplace setting discussed previously. This linearization yields a closed-form Gaussian on both the networks weights and the output, which [16] use to find the subspace projection matrix PP by minimizing the discrepancy between the output covariance of the subspace model and that of the full Laplace approximation. However, the exact construction requires access to quantities that are generally inaccessible for large neural networks, including the full (GGN) curvature matrix and an eigendecomposition of the full output covariance. In practice, scalable variants therefore rely on additional approximations such as diagonal or Kronecker-factored curvature estimates [33].

Our goal is different. Rather than computing the output covariance of the full Laplace approximation, we construct a generalized-Bayes Laplace approximation directly in a curvature informed active subspace. The posterior samples are propagated through the non-linear network itself rather than through a linearized predictive model. This distinction is important since linearized Laplace methods keep the posterior predictive mean anchored at the MAP prediction (see § 4.1.8), and can thereby avoid the underfitting behaviour observed when non-linear weight samples are propagated through the network. In our non-linear predictive setting, the size and coherence of the sampled parameter perturbations are therefore central; if the calibrated posterior requires many weak-curvature directions, the resulting samples may leave the local region in which the Laplace approximation is reliable. The generalized Bayesian scaling mitigates this effect by achieving calibrated coverage with a much smaller active subspace, thereby reducing both non-linear sampling artifacts and the number of curvature-vector products required.

Also, the authors of [16] shows that a low-dimensional subspace can approximate the full predictive covariance of the linearized Laplace approximation, but the required subspace dimensions are still in the tens to hundreds in their experiments. While this is tiny compared to the size of the full weight space, our generalized-Bayes active subspace often achieves calibrated coverage with only a handful of curvature directions, preserving the intended low-rank character of the approximation.

There are a number of other contributions that use the Laplace approximation of the posterior. The authors of [34] proposed a scalable Laplace approximation for neural networks using the aforementioned Kronecker-factored curvature estimates of [33]. This approach improves scalability by imposing a layer-wise Kronecker structure on the curvature, whereas our method obtains scalability by restricting the posterior to a low-rank generalized Gauss–Newton active subspace. Consequently, our approach does not require layer-wise Kronecker independence assumptions. The broader practical relevance of Laplace approximations for Bayesian deep learning has been demonstrated by [35], whose authors review and benchmark several scalable Laplace variants and provide a dedicated laplace PyTorch library.

Related active-subspace approaches based on variational inference include [18] and [36]. These methods draw on the classical active-subspace construction, in which the subspace is identified from an uncentered covariance of model gradients [13]. This matrix is typically averaged over a prescribed prior weight distribution. In contrast, our active subspace can be viewed as a Monte Carlo approximation of a data-averaged local curvature matrix. Specifically, the generalized Gauss–Newton matrix is an empirical average over the training data, evaluated at the pretrained weights. Thus, unlike prior-averaged active-subspace constructions, our subspace is tied directly to the local data-fit geometry that also defines the generalized Laplace approximation.

Methods

We now describe the methodological details of the proposed low-rank generalized Laplace framework for uncertainty quantification in neural networks.

Statistics

Our method starts from a generalized Bayesian posterior defined through the empirical mean loss, rather than the summed negative log-likelihood used in standard Bayesian analysis. Around a pretrained set of weights, we then construct a Laplace approximation whose covariance is determined by the local curvature of the loss. Since the full Hessian is intractable and may be indefinite, we replace it by a positive semi-definite generalized Gauss–Newton approximation [37] and compute its dominant eigenspace using matrix-free products computed with automatic differentiation. The resulting Gaussian posterior is restricted to this low-dimensional active subspace, with the prior variance calibrated by an empirical generalized-Bayes evidence criterion. We end with a discussion on posterior sampling strategies.

Generalized Bayes formulation

To define a posterior update, a mechanism to connect the parameters to the data is required. In a generalized Bayesian setting this is achieved via a loss function rather than through a traditional likelihood function. This allows us to construct a generalized posterior based on the empirical mean loss while retaining the familiar structure of a prior-to-posterior belief update. We define the mean loss function as

LN(θ,y)=1N∑n=1Nln(θ,yn).(11)\mathcal{L}_N(\theta, y) = \frac{1}{N} \sum_{n=1}^{N} l_n(\theta, y_n). \tag*{(11)}

We will consider:

ln=12∑m=1M(yn(m)−fn(m))2andln=−∑m=1Myn(m)log⁡pn(m),(12)l_n = \frac{1}{2} \sum_{m=1}^{M} \left(y_n^{(m)} - f_n^{(m)}\right)^2 \qquad\text{and} \qquad l_n = - \sum_{m=1}^{M} y_n^{(m)} \log p_n^{(m)}, \tag*{(12)}

i.e. squared-loss and cross-entropy loss terms for regression and classification respectively. In the former yn∈RMy_n \in\mathbb{R}^{M} are the (noisy) observations of the true process, whereas in the latter yny_n is the MM-dimensional one-hot encoded vector with yn(m)=1y_n^{(m)} = 1 for m=cm = c and yn(m)=0y_n^{(m)} = 0 for m≠cm \ne c, cc being the index of the correct class. Here, the neural-network outputs fn(m):=f(m)(xn;θ)f_n^{(m)} := f^{(m)}(x_n; \theta) are the logits that determine the softmax probabilities

pn(m)=exp⁡(fn(m))∑jexp⁡(fn(j)).(13)p_n^{(m)} = \frac{\exp(f_n^{(m)})}{\sum_j \exp(f_n^{(j)})}. \tag*{(13)}

The generalized Bayesian (unnormalized) posterior is given by [14] as:

π~β(θ∣y)=exp⁡[−βLN(θ,y)]p(θ),(14)\widetilde{\pi}_{\beta}(\theta\mid y) = \exp\left[-\beta\mathcal{L}_N(\theta, y)\right]p(\theta), \tag*{(14)}

where we assume the following prior:

p(θ)=N(0,σ02ID).(15)p(\theta) = \mathcal{N}\left(0, \sigma_0^2 I_D\right). \tag*{(15)}

Here, IDI_D is the DD-dimensional identity matrix and β>0\beta> 0 is a so-called temperature parameter, which typically is a hyper parameter used to control how random the output of a neural networks is. Here we will use it to distinguish between generalized and standard Bayesian setting. Further note that the prior variance of the connection weights σ02∈R\sigma_0^2 \in\mathbb{R} will play an important role in subsequent analysis. Finally, we write the normalized posterior as πβ=π~β/Zβ\pi_\beta= \widetilde{\pi}_\beta/Z_\beta, with the normalizing constant ZβZ_\beta denoted as the marginal likelihood or the evidence.

In the case of a regression problem with Gaussian noise, the following statistical model is often assumed to relate the model ff to the data yy;

yn=f(xn;θ)+ϵn,ϵn∼N(0,σ2IM).(16)y_n = f(x_n; \theta) + \epsilon_n, \qquad\epsilon_n \sim\mathcal{N}\left(0, \sigma^2 I_M\right). \tag*{(16)}

Here, σ2\sigma^2 is the noise variance, which is assumed known, or estimated from residuals. Under this model, the standard Bayesian posterior is recovered by setting β=Nσ−2\beta= N\sigma^{-2} in (14), which is equivalent to replacing LN\mathcal{L}_N with a summed loss. In contrast, the generalized posterior based on the mean squared loss is obtained using β=σ−2\beta= \sigma^{-2}. For classification with softmax cross-entropy, there is no analogous Gaussian noise variance. Similarly, β=N\beta= N corresponds to the summed categorical negative log-likelihood of the standard Bayesian posterior, whereas the generalized posterior based on the mean cross-entropy loss requires β=1\beta= 1.

Laplace approximation of the generalized posterior

We define lβ(θ)l_\beta(\theta) as the negative log of (14), i.e.;

lβ(θ):=−log⁡π~β=βLN−log⁡p(θ)∝βLN+12σ02∥θ∥22.(17)l_\beta(\theta) := -\log\widetilde{\pi}_\beta= \beta\mathcal{L}_N - \log p(\theta) \propto\beta\mathcal{L}_N + \frac{1}{2\sigma_0^2}\lVert\theta\rVert_2^2. \tag*{(17)}

The most-likely maximum a-posteriori (MAP) parameter value solves

θ^=arg⁡min⁡θ lβ(θ).(18)\hat{\theta} = \underset{\theta}{\arg\min}\ l_\beta(\theta). \tag*{(18)}

We will use the pretrained weights θ0\theta_0 in place of the MAP value, which is a common approximation (also used by e.g. [34] and [15]) unless the network was trained using L2L2 weight decay with regularization strength consistent with the values of 1/(2σ02)1/(2\sigma_0^2) and β\beta. In our approach, θ0\theta_0 serves as the anchor point for the Laplace approximation, originally applied by [12] to small neural networks. This approximation models the posterior distribution πβ(θ∣y)\pi_\beta(\theta\mid y) as a Gaussian distribution, with a covariance structure defined from (the inverse of) the curvature of the log-likelihood function. The underpinning idea here is that the log likelihood quickly drops away (i.e. has high curvature) when the data is able to inform the parameters well. For generalized Bayes, the covariance structure is derived from the curvature of the loss function instead. To arrive at such an expression a second-order Taylor expansion of lβ(θ)l_\beta(\theta) around θ0\theta_0 is made

lβ(θ)≈lβ(θ0)+12(θ−θ0)T∇θ2lβ(θ0)(θ−θ0),(19)l_\beta(\theta) \approx l_\beta(\theta_0) + \frac{1}{2}(\theta-\theta_0)^{T}\nabla_\theta^2 l_\beta(\theta_0)(\theta-\theta_0), \tag*{(19)}

where under the assumption that θ0\theta_0 is sufficiently close to a stationary point of lβl_\beta, the first-order term drops out: ∇θlβ(θ0)=0\nabla_\theta l_\beta(\theta_0) = 0. Given (19), the posterior πβ\pi_\beta now becomes a Gaussian N(θ0,Σ)\mathcal{N}(\theta_0,\Sigma):

πβ(θ∣y)∝exp⁡[−lβ(θ)]∝exp⁡[−12(θ−θ0)TΣ−1(θ−θ0)],(20)\pi_\beta(\theta\mid y) \propto\exp[-l_\beta(\theta)] \propto\exp\left[-\frac{1}{2}(\theta-\theta_0)^{T}\Sigma^{-1}(\theta-\theta_0)\right], \tag*{(20)}

with

Σ=(∇θ2lβ(θ0))−1=(β∇θ2LN(θ0)−∇θ2log⁡p(θ))−1=(βHL+1σ02ID)−1.(21)\Sigma= \left(\nabla_\theta^2 l_\beta(\theta_0)\right)^{-1} = \left(\beta\nabla_\theta^2\mathcal{L}_N(\theta_0)-\nabla_\theta^2\log p(\theta)\right)^{-1} = \left(\beta H_L+\frac{1}{\sigma_0^2}I_D\right)^{-1}. \tag*{(21)}

Note that here HLH_L is defined to be the Hessian of the mean loss, HL:=∇θ2LN(θ0)∈RD×DH_L := \nabla_\theta^2\mathcal{L}_N(\theta_0) \in\mathbb{R}^{D\times D}.

The Gaussian form is thus a consequence of truncating the Taylor expansion around θ0\theta_0 at the quadratic term, it is not statement that the full neural-network posterior is indeed normally distributed, which may well be multi modal and non-Gaussian. The Laplace approximation is therefore a pragmatic, local posterior estimate around one trained solution, not as a faithful global description of all plausible weights. We examine its usefulness through its posterior predictive behaviour, i.e. by the resulting posterior distribution of the neural-network output.

The Laplace approximation gives a closed-form expression for the posterior on θ\theta. Unlike UQ approaches based on (low-rank) variational inference (e.g. [18, 36]), no additional training is therefore required. Still, computing and inverting HLH_L is computationally intractable in neural networks due to the size of θ\theta. To overcome this limitation we will construct a computationally tractable closed-form expression for the posterior variance.

Low-rank posterior variance

By examining (21), we observe that in the principal coordinate system spanned by the eigenvectors from HLpj=λjpjH_L p_j = \lambda_j p_j, the posterior variances σj2\sigma_j^2 become;

σj2=1βλj+σ0−2,j=1⋯ ,D.(22)\sigma_j^2 = \frac{1}{\beta\lambda_j + \sigma_0^{-2}}, \qquad j = 1 \cdots, D. \tag*{(22)}

In practice, a low-rank framework is obtained by retaining only the first d≪Dd \ll D dominant eigenvalues λj\lambda_j of an approximation to the Hessian. The quality of this approximation depends on how well the approximate Hessian captures directions of significant curvature (see § 4.1.4), as well as on the choice of prior variance σ02\sigma_0^2.

It is not uncommon to find references which discuss Hessian approximations in the context of the sum loss, see e.g. [37]. As discussed, in the present work we use the loss from generalized Bayes rather than the summed negative log-likelihood. This corresponds to a temperature-scaled posterior where the parameter β\beta controls how strongly the data loss is weighted relative to the prior (see (14)). For β=σ−2\beta= \sigma^{-2} or β=1\beta= 1 (mean regression / classification loss), the likelihood contribution is normalized by the number of data points. This normalization prevents the curvature eigenvalues from scaling linearly with NN, such that the curvature is governed by the shape of the mean loss landscape, not by the size of the dataset. This is important in our low-rank subspace setting, since as NN increases, the posterior variances (22) decrease in the standard Bayesian setting with β=Nσ−2\beta= N\sigma^{-2} or β=N\beta= N. While in this setting posterior contraction is expected as NN grows, in a low-rank projected posterior this can become too aggressive, and the leading active directions become extremely narrow. Using the mean loss avoids this purely sample-size-driven contraction. It makes the eigenvalues describe the average local sensitivity of the trained model rather than the total accumulated data-fit curvature.

Regardless of the choice of β\beta, the form σj2=(βλj+1/σ02)−1\sigma_j^2 = (\beta\lambda_j + 1/\sigma_0^2)^{-1} highlights the interplay between data and prior. Directions with large average curvature (large λj\lambda_j) lead to stronger posterior contraction, while in flat directions (λj→0\lambda_j \to0) the posterior variance reverts to the prior, σj2→σ02\sigma_j^2 \to\sigma_0^2. Thus, the prior variance acts as a baseline level of uncertainty in directions not informed by the data.

Since σ02\sigma_0^2 appears explicitly in the posterior variance and controls the overall scale of uncertainty, it must be chosen carefully. We estimate σ02\sigma_0^2 using an empirical Bayes procedure in Section 4.1.6. First, we discuss common choices for the approximate Hessian, and means to efficiently extract their dd dominant eigenpairs.

Approximate Hessians

In general, an issue with using the true Hessian in the covariance expression is that it is not guaranteed to be positive semi-definite. Several approximations are therefore commonly employed, most notably the generalized Gauss–Newton matrix GG, which coincides with the true Hessian only under specific assumptions [37]. Understanding the precise conditions under which these matrices agree, and how they differ otherwise, is essential for justifying their use as curvature surrogates. In the following, we briefly make these relationships explicit and discuss their implications for subspace-based uncertainty quantification.

One can decompose the Hessian into a term involving second derivatives of the model output, and a (more tractable) term that depends only on first-order derivatives. A natural approach is to apply the chain rule to (11), differentiating with respect to ff before taking the θ\theta derivative. The resulting gradient will have entries

(∇θLN)i=1N∑n=1N∑m=1Mrn(m)∂fn(m)∂θi,i=1,…,D,(23)(\nabla_\theta\mathcal{L}_N)_i = \frac{1}{N}\sum_{n=1}^{N}\sum_{m=1}^{M} r_n^{(m)} \frac{\partial f_n^{(m)}}{\partial\theta_i}, \qquad i=1,\ldots,D, \tag*{(23)}

where rn(m)r_n^{(m)} are residuals, defined as:

rn(m):=fn(m)−yn(m)orrn(m):=pn(m)−yn(m),(24)r_n^{(m)} := f_n^{(m)} - y_n^{(m)} \quad\text{or} \quad r_n^{(m)} := p_n^{(m)} - y_n^{(m)}, \tag*{(24)}

for regression or classification. Note that for the latter, rn(m)r_n^{(m)} is a probability residual, which unlike its regression counterpart, is a function of all MM fn(m)f_n^{(m)} entries (see (13)). Applying the chain rule to (23) once more gives the Hessian entries:

(∇θ2LN)i,j=1N∑n∑m(rn(m)∂2fn(m)∂θi∂θj+∑k∂rn(m)∂fn(k)∂fn(k)∂θi∂fn(m)∂θj),i,j=1,…,D.(25)(\nabla_\theta^2 \mathcal{L}_N)_{i,j} = \frac{1}{N}\sum_n\sum_m \left(r_n^{(m)} \frac{\partial^2 f_n^{(m)}}{\partial\theta_i\partial\theta_j} + \sum_k \frac{\partial r_n^{(m)}}{\partial f_n^{(k)}} \frac{\partial f_n^{(k)}}{\partial\theta_i}\frac{\partial f_n^{(m)}}{\partial\theta_j}\right), \qquad i,j=1,\ldots,D. \tag*{(25)}

When written in matrix form we obtain:

HL(θ):=∇θ2LN=1N∑n∑mrn(m)∇θ2fn(m)+1N∑n(∇θfn)THℓn(∇θfn).(26)H_L(\theta) := \nabla_\theta^2\mathcal{L}_N = \frac{1}{N}\sum_n\sum_m r_n^{(m)}\nabla_\theta^2 f_n^{(m)} + \frac{1}{N}\sum_n(\nabla_\theta f_n)^T H_{\ell_n}(\nabla_\theta f_n). \tag*{(26)}

Here, ∇θfn∈RM×D\nabla_{\theta} f_n \in\mathbb{R}^{M \times D} is the Jacobian of the output, and Hln:=∇fn2ln∈RM×MH_{l_n} := \nabla^2_{f_n} l_n \in\mathbb{R}^{M \times M} is a Hessian with (Hln)m,k=∂2ln/∂fn(m)∂fn(k)=∂rn(m)/∂fn(k)(H_{l_n})_{m,k} = \partial^2 l_n / \partial f_n^{(m)} \partial f_n^{(k)} = \partial r_n^{(m)} / \partial f_n^{(k)}, leading to

Hln=IMandHln=diag⁡(pn)−pnpnT(27)H_{l_n} = I_M \quad\text{and} \quad H_{l_n} = \operatorname{diag}(p_n) - p_n p_n^{T} \tag*{(27)}

for regression and classification respectively.

The generalized Gauss–Newton (GGN) matrix GG is an approximation to HLH_L that captures (partial) curvature information while avoiding second-order derivatives of the model, and is obtained by simply ignoring the first term of (26);

HL(θ)≈G(θ):=1N∑n(∇θfn)THln(∇θfn).(28)H_L(\theta) \approx G(\theta) := \frac{1}{N} \sum_n (\nabla_{\theta} f_n)^T H_{l_n} (\nabla_{\theta} f_n). \tag*{(28)}

This is convenient as it drops the (expensive) Hessians of fn(m)f_n^{(m)}. Moreover, from (26) we can see that this is a well-justified approximation as argued by [37], in the sense that the neglected term vanishes when the residuals are small. For (28) to be exact, it would be sufficient if all residuals are zero. However, this is unrealistic, and would be indicative of overfitting. The authors of [15] therefore prefer an alternative justification for the use of GG, namely that it is equivalent to replacing the network by its first-order Taylor expansion flinf_{\mathrm{lin}} around θ0\theta_0, for which ∇θ2flin(θ0)=0\nabla^2_{\theta} f_{\mathrm{lin}}(\theta_0) = 0 holds. This leads to so-called linearized Laplace predictive distributions, discussed in § 4.1.8.

Finally, we note that empirical work has shown that the loss gradient ∇θLN\nabla_{\theta} \mathcal{L}_N aligns strongly with the leading eigenvectors of the Hessian, see [38], implying that optimization proceeds primarily within a subspace spanned by a small number of dominant curvature directions. This observation provides support for low-rank posterior approximations involving (approximate) Hessians; if training mainly explores a restricted subspace, then uncertainty quantification should focus on these same directions. Our approach leverages this structure by constructing a posterior covariance aligned with the dominant eigenspace of G(θ)G(\theta). As mentioned, we use the term active subspace to denote the dominant eigenspace of the generalized Gauss–Newton curvature of the empirical mean loss, which is a slight departure from its original definition [13]. That said, the overarching idea is similar, as is the linear projection to the active subspace;

w0=PTθ0∈Rd,(29)w_0 = P^T \theta_0 \in\mathbb{R}^d, \tag*{(29)}

here applied to the connection weights. P∈RD×dP \in\mathbb{R}^{D \times d} contains the d≪Dd \ll D dominant (orthonormal) eigenvectors of GG. In order to form PP for large neural networks, we first discuss matrix-free eigenvalue methods.

Matrix-free computation of dominant eigenpairs

In practice, computing the dominant eigenvalues / vectors of G∈RD×DG \in\mathbb{R}^{D \times D} will be complicated by the dimension of GG. For large enough DD, even storing GG in memory will not be possible. However, we can use the Lanczos algorithm [39, 40] to approximate the leading eigenpairs, which only requires access to matrix-vector products GvGv. These products can be computed using automatic differentiation without ever forming GG. If we write Jn:=∇θfn∈RM×DJ_n := \nabla_\theta f_n \in\mathbb{R}^{M \times D} for brevity, we obtain

Gv=1N∑nJnTHlnJnv,(30)Gv = \frac{1}{N}\sum_n J_n^T H_{l_n}J_nv, \tag*{(30)}

see (28). In general, by the chain rule, the Jacobian-vector product Jnv∈RM×1J_nv \in\mathbb{R}^{M \times1} equals

Jnv=ddϵf(xn;θ+ϵv)∣ϵ=0,J_nv = \left.\frac{\mathrm{d}}{\mathrm{d}\epsilon}f(x_n;\theta+\epsilon v)\right|_{\epsilon=0},

which in turn can be computed with forward-mode automatic differentiation, see e.g. [41]. Once JnvJ_nv is available at the output, pre-multiplication with the known HlnH_{l_n} (27) yields un:=HlnJnv∈RM×1u_n := H_{l_n}J_nv \in\mathbb{R}^{M \times1}. If we define the auxiliary scalar loss function L~:=unTf\tilde{L} := u_n^T f such that its derivative equals dL~/df=un\mathrm{d}\tilde{L}/\mathrm{d}f = u_n, then once again by the chain rule;

dL~dθ=JnTun=JnTHlnJnv∈RD,\frac{\mathrm{d}\tilde{L}}{\mathrm{d}\theta} = J_n^T u_n = J_n^T H_{l_n}J_nv \in\mathbb{R}^D,

which equals the nn-th term of (30) and can be computed using standard back propagation. Hence, each of the NN contributions to GvGv can be evaluated using one forward- and one backward-pass through the network, without ever explicitly forming the Jacobian JnJ_n or the matrix GG. In practice one uses mini-batches in place of a term-by-term computation. In addition, libraries such as PyTorch have dedicated subroutines for computing the required Jacobian-vector products.

Access to GvGv enables scalable computation of the dominant eigenspace of GG in high-dimensional settings. Briefly, we use the Lanczos algorithm, a well-known iterative method for approximating a few extremal eigenvalues and eigenvectors of a symmetric matrix G∈RD×DG \in\mathbb{R}^{D \times D} using only matrix–vector products. Starting from an initial unit vector v1v_1, it constructs an orthonormal basis {v1,…,vl}\{v_1,\ldots,v_l\} of the Krylov subspace span⁡{v1,Gv1,…,Gl−1v1}\operatorname{span}\{v_1,Gv_1,\ldots,G^{l-1}v_1\} via the recursion

vk+1=Gvk−bk−1vk−1−akvkbk,bk=∥Gvk−bk−1vk−1−akvk∥2,ak=vkTGvk.(31)v_{k+1} = \frac{Gv_k-b_{k-1}v_{k-1}-a_kv_k}{b_k}, \qquad b_k = \lVert Gv_k-b_{k-1}v_{k-1}-a_kv_k\rVert_2,\quad a_k=v_k^TGv_k. \tag*{(31)}

with b0=0b_0 = 0, which follows from a Gram-Schmidt procedure. This yields a low-dimensional symmetric tridiagonal matrix Tl∈Rl×lT_l \in\mathbb{R}^{l \times l} with d<l≪Dd < l \ll D constructed from ak,bka_k,b_k coefficients (see e.g. [39]) for which

Tl=VlTGVl(32)T_l = V_l^TGV_l \tag*{(32)}

holds, where Vl=[v1,…,vl]∈RD×lV_l = [v_1,\ldots,v_l] \in\mathbb{R}^{D \times l}. The eigenvalues of TlT_l directly approximate the leading eigenvalues of GG, and VlUl∈RD×lV_lU_l \in\mathbb{R}^{D \times l} approximate the corresponding eigenvectors, Ul∈Rl×lU_l \in\mathbb{R}^{l \times l} being the eigenvectors of TlT_l.

The first dd columns of VlUlV_lU_l define our projection matrix P∈RD×dP \in\mathbb{R}^{D \times d}. Note that in order to bring the error down as in Figure 2, it is important to select a sufficiently high number of basis functions l>dl > d to span the Krylov subspace. We used l=d+10l = d + 10. Crucially, note that the method requires only repeated evaluations of GvGv, making it well-suited for large-scale settings where GG cannot be formed explicitly.

Empirical generalized Bayesian subspace inference for the prior variance

As previously mentioned, the value of the prior variance plays an important role in (22), and must be chosen with care. However, defining a plausible prior on the connection weights θ\theta is challenging due to their lack of physical meaning. Empirical Bayesian inference [42] provides a solution in this context by allowing us to estimate σ02\sigma_0^2 directly from the data yy. That said, the severe overparameterization of neural networks again poses specific challenges. We found that applying empirical Bayes directly in the full, high-dimensional parameter space forces the optimization toward excessively high σ0\sigma_0 values to compensate for the many D−dD - d flat, uninformative directions. To resolve this, we perform empirical Bayes in the projected parameter space defined by the active subspace w=PTθ∈Rdw = P^T\theta\in\mathbb{R}^d. Again, let P∈RD×dP \in\mathbb{R}^{D \times d} contain the dominant eigenvectors of GG and define

w0=PTθ0,θ(w)=θ0+P(w−w0).(33)w_0 = P^T\theta_0,\qquad\theta(w) = \theta_0 + P(w - w_0). \tag*{(33)}

The loss restricted to the active subspace is then

LN(w,y):=LN(θ(w),y)\mathcal{L}_N(w,y) := \mathcal{L}_N(\theta(w),y)

Our analysis will proceed similar to § 4.1.2. Let π~β,w\tilde{\pi}_{\beta,w} be the generalized unnormalized posterior in the ww subspace, i.e.,

π~β,w(w∣y,σ02)=exp⁡[−βLN(w,y)]p(w∣σ02),(34)\tilde{\pi}_{\beta,w}(w \mid y,\sigma_0^2) = \exp[-\beta\mathcal{L}_N(w,y)]p(w \mid\sigma_0^2), \tag*{(34)}

with the prior p(w∣σ02)=N(0,σ02Id)p(w \mid\sigma_0^2) = \mathcal{N}(0,\sigma_0^2 I_d). We find σ02\sigma_0^2 by maximizing the generalized evidence:

Zβ,w(y∣σ02)=∫π~β,w(w∣y,σ02) dw.(35)Z_{\beta,w}(y \mid\sigma_0^2) = \int\tilde{\pi}_{\beta,w}(w \mid y,\sigma_0^2)\,\mathrm{d}w. \tag*{(35)}

The log density is given by

log⁡Zβ,w(y∣σ02)=log⁡∫exp⁡[−lw(w∣σ02)] dw.(36)\log Z_{\beta,w}(y \mid\sigma_0^2) = \log\int\exp[-l_w(w \mid\sigma_0^2)]\,\mathrm{d}w. \tag*{(36)}

with lw(w∣σ02)l_w(w \mid\sigma_0^2) defined as the negative log unnormalized generalized posterior density:

lw:=−log⁡π~β,w(w∣σ02)=βLN(w,y)−log⁡p(w∣σ02)(37)l_w := -\log\tilde{\pi}_{\beta,w}(w \mid\sigma_0^2) = \beta\mathcal{L}_N(w,y) - \log p(w \mid\sigma_0^2) \tag*{(37)}

We now insert a Taylor expansion for lwl_w around w0=PTθ0w_0 = P^T\theta_0 into (36), to give rise to a Laplace approximation;

log⁡Zβ,w(y∣σ02)≈−lw(w0∣σ02)+log⁡∫exp⁡[−12(w−w0)T[∇w2lw(w0)](w−w0)] dw.(38)\log Z_{\beta,w}(y \mid\sigma_0^2) \approx-l_w(w_0 \mid\sigma_0^2) + \log\int\exp\left[-\frac{1}{2}(w-w_0)^T\left[\nabla_w^2 l_w(w_0)\right](w-w_0)\right]\,dw. \tag*{(38)}

As in the full-space Laplace approximation, we assume that w0w_0 is sufficiently close to a stationary point of lwl_w, so that the first-order term in the Taylor expansion can be neglected. The second log term contains the integral of the unnormalized Laplace posterior in the active subspace, with ∇w2lw=PT∇θ2lβP=PT[β∇θ2LN−∇θ2log⁡p(θ0∣σ02)]P=βPTHLP+σ0−2Id\nabla_w^2 l_w = P^T\nabla_\theta^2 l_\beta P = P^T[\beta\nabla_\theta^2\mathcal{L}_N-\nabla_\theta^2\log p(\theta_0\mid\sigma_0^2)]P = \beta P^T H_LP+\sigma_0^{-2}I_d, and therefore equals the reciprocal of the Gaussian normalizing constant. Defining Hw:=PTHLPH_w := P^T H_LP, (38) then becomes;

log⁡Zβ,w(y∣σ02)∝−lw(w0∣σ02)−12log⁡(det⁡[βHw+1σ02Id])∝−βLN(w0,y)+log⁡p(w0∣σ02)−12log⁡(det⁡[βHw+1σ02Id])∝log⁡p(w0∣σ02)−12log⁡(det⁡[βHw+1σ02Id])∝−12σ02∥w0∥22−dlog⁡σ0−12∑i=1dlog⁡(βλi+1σ02),(39)\begin{aligned} \log Z_{\beta,w}(y\mid\sigma_0^2) &\propto-l_w(w_0\mid\sigma_0^2)-\frac{1}{2}\log\left(\det\left[\beta H_w+\frac{1}{\sigma_0^2}I_d\right]\right)\\ &\propto-\beta\mathcal{L}_N(w_0,y)+\log p(w_0\mid\sigma_0^2)-\frac{1}{2}\log\left(\det\left[\beta H_w+\frac{1}{\sigma_0^2}I_d\right]\right)\\ &\propto\log p(w_0\mid\sigma_0^2)-\frac{1}{2}\log\left(\det\left[\beta H_w+\frac{1}{\sigma_0^2}I_d\right]\right)\\ &\propto-\frac{1}{2\sigma_0^2}\lVert w_0\rVert_2^2-d\log\sigma_0-\frac{1}{2}\sum_{i=1}^{d}\log\left(\beta\lambda_i+\frac{1}{\sigma_0^2}\right), \tag*{(39)} \end{aligned}

The loss LN\mathcal{L}_N does not depend explicitly on σ02\sigma_0^2, and is therefore considered constant in this approximation. In the last line we swap out HLH_L with an approximate Hessian discussed in § 4.1.4 (i.e. Hw≈PTGPH_w\approx P^TGP), and the low-rank structure of HwH_w allows us to then compute the determinant using only the dd dominant eigenvalues obtained from the matrix-free method of § 4.1.5. Setting α=σ0−2\alpha=\sigma_0^{-2}, we now find that

0=ddα(−α2∥w0∥22+d2log⁡α−12∑i=1dlog⁡(βλi+α))=−12∥w0∥22+d2α−12∑i=1d1βλi+α.(40)\begin{aligned} 0 &= \frac{d}{d\alpha}\left(-\frac{\alpha}{2}\lVert w_0\rVert_2^2+\frac{d}{2}\log\alpha-\frac{1}{2}\sum_{i=1}^{d}\log(\beta\lambda_i+\alpha)\right)\\ &=-\frac{1}{2}\lVert w_0\rVert_2^2+\frac{d}{2\alpha}-\frac{1}{2}\sum_{i=1}^{d}\frac{1}{\beta\lambda_i+\alpha}. \tag*{(40)} \end{aligned}

Solving for the projected weight norm;

∥w0∥22=∑i=1d1α−1βλi+α=∑i=1dσ02−σi2,(41)\lVert w_0\rVert_2^2=\sum_{i=1}^{d}\frac{1}{\alpha}-\frac{1}{\beta\lambda_i+\alpha}=\sum_{i=1}^{d}\sigma_0^2-\sigma_i^2, \tag*{(41)}

with σi2\sigma_i^2 being the posterior variance (22). Therefore, the resulting σ02\sigma_0^2 sets the prior scale such that the magnitude of the projected parameter vector is consistent with the amount of variance reduction in the active subspace.

Note that performing this analysis in the full parameter space will lead to an expression involving ∥θ0∥22\lVert\theta_0\rVert_2^2 in place of ∥w0∥22\lVert w_0\rVert_2^2, which will be very large for overparameterized neural networks. This then leads to an excessively large prior variance σ02\sigma_0^2.

Although (41) defines an implicit and non-linear equation for σ02\sigma_0^2, the corresponding function is smooth and strictly decreasing in α\alpha, and therefore admits a unique solution. This solution can be efficiently obtained using standard one-dimensional root-finding methods (we use the bisection method).

Calibrating d

The dimension of the active subspace dd is a hyperparameter that must be set. For regression problems, we will do so by evaluating the coverage of the output confidence intervals on a calibration data set (xn∗,yn∗)(x_n^*, y_n^*), n=1,⋯ ,Ncaln = 1, \cdots, N_{\mathrm{cal}}. Let Iγ(x)I_\gamma(x) be the 1−γ1-\gamma confidence interval for γ∈[0,1]\gamma\in[0,1]. Our value of dd minimizes

d∗=arg⁡min⁡d 1Ncal∑n=1Ncal1[yn∗∈Iγ(xn∗)]≥1−γ.(42)d^* = \underset{d}{\arg\min}\ \frac{1}{N_{\mathrm{cal}}}\sum_{n=1}^{N_{\mathrm{cal}}} \mathbb{1}\left[y_n^* \in I_\gamma(x_n^*)\right] \ge1-\gamma. \tag*{(42)}

Here 1[A]\mathbb{1}[A] is an indicator function returning 1/0 if AA is true/false. Note that for each dd, we must perform the empirical Bayesian analysis of § 4.1.6, such that dd and σ0\sigma_0 are estimated jointly. Calibration in the context of classification entails making sure the correct class in contained in the 1−γ1-\gamma set with (approximately) probability 1−γ1-\gamma.

A similar calibration procedure can be applied to a classification network [29, 43]. However, if a classification network is already well calibrated, the additional stochasticity introduced via weight perturbations may diminish calibration, see the Discussion section.

Posterior prediction

The posterior variance (22) corresponds to the Laplace approximation restricted to the dominant eigenspace of the curvature matrix. In the full parameter space, directions orthogonal to this subspace have variance σ02\sigma_0^2, corresponding to the prior. While these directions are individually flat, they are vast in number (D−d≫dD-d \gg d), and can collectively contribute significantly to predictive uncertainty, often resulting in overly wide confidence intervals when posterior samples are propagated through the non-linear network.

Similar to e.g. [16, 18], we therefore omit these directions and obtain a low-rank approximation that concentrates uncertainty in the data-informed subspace. Sampling from this approximate posterior is then performed via

θ=θ0+Pz,z∼N(0,diag⁡(σj2)),σj2=1βλj+σ0−2,j=1,⋯ ,d.(43)\theta= \theta_0 + Pz,\quad z \sim\mathcal{N}\left(0,\operatorname{diag}(\sigma_j^2)\right),\quad\sigma_j^2 = \frac{1}{\beta\lambda_j+\sigma_0^{-2}},\quad j=1,\cdots,d. \tag*{(43)}

Using these samples during a forward pass we can approximate expectations such as

f(x∣y)=∫f(x;θ)πβ(θ∣y) dθ,(44)f(x \mid y) = \int f(x;\theta)\pi_{\beta}(\theta\mid y)\,\mathrm{d}\theta, \tag*{(44)}

via Monte Carlo sampling, pushing the Laplace posterior through the network. As the Laplace posterior is an approximation, the non linear nature of the network may push the mean prediction away from the MAP prediction.

This underfitting problem of sampled Laplace does not primarily mean that the Gaussian posterior family is insufficiently expressive. Rather, it refers to a degradation of the posterior predictive mean caused by propagating local Gaussian weight samples through the non-linear network. As mention in § 4.1.4, linearized Laplace [15] avoids this by making the a local linear approximation in the predictive model, thereby keeping the posterior predictive mean fixed at the MAP prediction:

f(x;θ)≈flin(x;θ)=f(x;θ0)+J(x)(θ−θ0),(45)f(x;\theta) \approx f_{\mathrm{lin}}(x;\theta) = f(x;\theta_0) + J(x)(\theta-\theta_0), \tag*{(45)}

where J(x):=∇θf(x;θ0)∈RM×DJ(x) := \nabla_{\theta}f(x;\theta_0) \in\mathbb{R}^{M \times D}. The combination of the linear output and the Gaussian distribution of θ\theta also leads a closed-form predictive covariance Σf=JΣJT\Sigma_f = J\Sigma J^{T}, where Σ=PAPT\Sigma= PAP^{T}, with Λ:=diag⁡(σj2)\Lambda:= \operatorname{diag}(\sigma_j^2) is our low-rank Laplace posterior covariance. In the case of scalar regression the (pointwise) posterior predictive variance becomes

σf2(x)=∑j=1dσj2(J(x)pj)2∈R,(46)\sigma_f^2(x) = \sum_{j=1}^{d}\sigma_j^2\left(J(x)p_j\right)^2 \in\mathbb{R}, \tag*{(46)}

with pj∈RDp_j \in\mathbb{R}^{D} denoting the j-th column vector of PP.

Supplementary information

For this article no Supplementary Materials are available.

Acknowledgements

We thank Dr Ketan Maheshwari at the US Department of Energy Oak Ridge National Laboratory and Dr Alessandro Tibo at AstraZeneca for helpful discussions and support with training REINVENT. We also thank Dr Laura Harbach at Brunel University London for initiating the REINVENT UQ study.

Declarations

Funding

P.V.C. is grateful for funding from the UK Engineering and Physical Sciences Research Council under the following project “UK Consortium on Mesoscale Engineering Sciences (UKCOMES)” (Grant No. EP/R029598/1).

Competing interests

The authors declare no competing interests.

Not applicable.

Not applicable.

Data and code availability

The data used to train the neural networks, a pre-trained REINVENT model and Jupyter notebooks to reproduce the results of this article are available at [17].

Materials availability

Not applicable.

Author contribution

W.N.E. developed the methodology, implemented the algorithms, performed the numerical experiments, analysed the results, and wrote the initial manuscript. P.V.C. contributed to the conceptual framing, interpretation of results, funding acquisition and manuscript revision. Both authors reviewed and approved the final manuscript.

Declaration on the use of artificial intelligence tools

The authors used OpenAI’s ChatGPT 5.5 as a tool for language editing. The tool was also used to discuss manuscript presentation, related-work positioning, and the interpretation of selected numerical results. All scientific claims, mathematical derivations, algorithms, references, numerical experiments, and conclusions were reviewed, verified, and finalized by the authors. The authors assume full responsibility for the content of the manuscript.

ChEMBL vocabulary

Here we describe the ChEMBL vocabulary in Table A1 and display some example chemical compounds in Table A2.

IndexTokenDescriptionIndexTokenDescription
0$ | Stop/end token | 17 | Br | Bromine atom
1^Start token18CAliphatic carbon atom
2#Triple bond19ClChlorine atom
3%10Two-digit ring closure20FFluorine atom
4(Branch opening21NAliphatic nitrogen atom
5)Branch closing22OOxygen atom
6-Single bond23SSulfur atom
71Ring closure index24[N+]Positively charged nitrogen
82Ring closure index25[N-]Negatively charged nitrogen
93Ring closure index26[O-]Negatively charged oxygen
104Ring closure index27[S+]Positively charged sulfur
115Ring closure index28[n+]Positively charged aromatic nitrogen
126Ring closure index29[nH]Protonated aromatic nitrogen
137Ring closure index30cAromatic carbon atom
148Ring closure index31nAromatic nitrogen atom
159Ring closure index32oAromatic oxygen atom
16=Double bond33sAromatic sulfur atom

Table A1. Vocabulary used by the autoregressive SMILES generator. The vocabulary contains start and stop tokens, bond symbols, branch symbols, ring-closure indices, atom tokens, and charged or aromatic atom tokens.

No.SMILES
1CC(C)C(NC(=O)C(NC(=O)C1OC2OC(C)(C)OC2C2OC(C)(C)OC12)C(C)C)C(O)=O
2Fc1ccc(cc1)C(=O)NN1C(SCc2ccc(cc2)N(=O)=O)=Nc2ccccc2C1=O
3CC(C)CN1Cc2cnnn2-c2ccc(cc2C1)-c1ccccc1
4CCN(C(=O)CSc1nnnn1-c1ccccc1)C1=C(N)N(Cc2ccccc2)C(=O)NC1=O
5CC(C)N1CCN(CC1)C(=O)N1c2ccccc2Sc2ccccc12
6CC1(C)Cc2cc(OCc3ccc(cc3)-c3nn[nH]n3)c(Cl)c(Cl)c2C1=O
7Cc1cccc(CSc2ccc(cn2)C(=O)Nc2ccc(F)cc2)c1F
8CCC(N1N=C(O)C2=Nc3cc(Cl)ccc3C(=O)C2=C1O)c1ccccn1
9CC(N1C(=O)C2OC3(C)C=C(C)C=NC3C2C1=O)c1ccccc1
10Cc1nc(cs1)-c1cccc(NC(=O)c2ccc3nc4C(=O)NCCCn4c3c2)c1

Table A2. 10 SMILES strings from the ChEMBL database.

References

  1. [1]Palmer, T.N.: Predicting uncertainty in forecasts of weather and climate. Reports on progress in Physics 63(2), 71–116 (2000)DOI
  2. [2]Murphy, J.M., Sexton, D.M.H., Barnett, D.N., Jones, G.S., Webb, M.J., Collins, M., Stainforth, D.A.: Quantification of modelling uncertainties in a large ensemble of climate change simulations. Nature 430(7001), 768–772 (2004)pubmed.ncbi.nlm.nih.gov/15306806
  3. [3]Cheung, S.H., Oliver, T.A., Prudencio, E.E., Prudhomme, S., Moser, R.D.: Bayesian uncertainty analysis with applications to turbulence modeling. Reliability Engineering & System Safety 96(9), 1137–1149 (2011)DOI
  4. [4]Gorlé, C., Iaccarino, G.: A framework for epistemic uncertainty quantification of turbulent scalar flux models for reynolds-averaged navier-stokes simulations. Physics of Fluids 25(5) (2013)DOI
  5. [5]Liu, X., Guillas, S.: Dimension reduction for Gaussian process emulation: An application to the influence of bathymetry on tsunami heights. SIAM/ASA Journal on Uncertainty Quantification 5(1), 787–812 (2017)arxiv.org/abs/1603.07888
  6. [6]Selva, J., Tonini, R., Molinari, I., Tiberti, M.M., Romano, F., Grezio, A., Melini, D., Piatanesi, A., Basili, R., Lorito, S.: Quantification of source uncertainties in seismic probabilistic tsunami hazard analysis (sptha). Geophysical Journal International 205(3), 1780–1803 (2016)
  7. [7]Avitabile, D., Cavallini, F., Dubinkina, S., Lord, G.J.: Neural field equations with random data. SIAM/ASA Journal on Uncertainty Quantification 14(2), 534–567 (2026)arxiv.org/abs/2505.16343
  8. [8]Edeling, W.N., Vassaux, M., Yang, Y., Wan, S., Guillas, S., Coveney, P.V.: Global ranking of the sensitivity of interaction potential contributions within classical molecular dynamics force fields. npj Computational Materials 10(1), 87 (2024)
  9. [9]Gelman, A.: Bayesian data analysis. Chapman and Hall/CRC (2013)
  10. [10]Blundell, C., Cornebise, J., Kavukcuoglu, K., Wierstra, D.: Weight uncertainty in neural network. In: International Conference on Machine Learning, pp. 1613–1622 (2015). PMLR
  11. [11]Fu, H., Li, C., Liu, X., Gao, J., Celikyilmaz, A., Carin, L.: Cyclical annealing schedule: A simple approach to mitigating KL vanishing. In: Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pp. 240–250 (2019)arxiv.org/abs/1903.10145
  12. [12]MacKay, D.J.C.: A practical Bayesian framework for backpropagation networks. Neural computation 4(3), 448–472 (1992)DOI
  13. [13]Constantine, P.G., Dow, E., Wang, Q.: Active subspace methods in theory and practice: applications to kriging surfaces. SIAM Journal on Scientific Computing 36(4), 1500–1524 (2014)
  14. [14]Bissiri, P.G., Holmes, C.C., Walker, S.G.: A general framework for updating belief distributions. Journal of the Royal Statistical Society Series B: Statistical Methodology 78(5), 1103–1130 (2016)
  15. [15]Immer, A., Korzepa, M., Bauer, M.: Improving predictions of Bayesian neural nets via local linearization. In: International Conference on Artificial Intelligence and Statistics, pp. 703–711 (2021). PMLR.arxiv.org/abs/2008.08400
  16. [16]Faller, J., Martin, J.: Low rank based subspace inference for the Laplace approximation of Bayesian neural networks. In: The 29th International Conference on Artificial Intelligence and Statistics (2026). https://openreview.net/forum?id=RTwTXQX4garxiv.org/abs/2502.02345
  17. [17]Edeling, W.N.: GLAS: Generalized Laplace Active Subspaces. https://github.com/wedeling/GLAS. GitHub repository (2026)
  18. [18]Jantre, S., Urban, N.M., Qian, X., Yoon, B.: Learning active subspaces for effective and scalable uncertainty quantification in deep neural networks. In: ICASSP 2024-2024 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), pp. 5330–5334 (2024). IEEEarxiv.org/abs/2309.03061
  19. [19]Kingma, D.P., Ba, J.: Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980 (2014)arxiv.org/abs/1412.6980
  20. [20]Aggarwal, C.C.: Neural Networks and Deep Learning vol. 10. Springer, ??? (2018)
  21. [21]Yeh, I.: Concrete Compressive Strength. UCI Machine Learning Repository. DOI: https://doi.org/10.24432/C5PK67 (1998)
  22. [22]Constantine, P.G., Diaz, P.: Global sensitivity metrics from active subspaces. Reliability Engineering & System Safety 162, 1–13 (2017)arxiv.org/abs/1510.04361
  23. [23]Olivecrona, M., Blaschke, T., Engkvist, O., Chen, H.: Molecular de-novo design through deep reinforcement learning. Journal of cheminformatics 9(1), 48 (2017)
  24. [24]Loeffler, H., He, J., Tibo, A., Janet, J.P., Voronov, A., Mervin, L.H., Engkvist, O.: Reinvent 4: Modern AI–driven generative molecule design. Journal of Cheminformatics 16(1), 20 (2024)
  25. [25]Gaulton, A., Hersey, A., Nowotka, M., Bento, A.P., Chambers, J., Mendez, D., Mutowo, P., Atkinson, F., Bellis, L.J., Cibrián-Uhalte, E., et al.: The ChEMBL database in 2017. Nucleic acids research 45(D1), 945–954 (2017)DOI
  26. [26]Landrum, G., Tosco, P., Kelley, B., Cosgrove, D., Vianello, R., Kawashima, E., Jones, G., Dalke, A., Cole, B., Swain, M., et al.: rdkit/rdkit: 2026_03_4. Zenodo (2026)
  27. [27]Lipinski, C.A., Lombardo, F., Dominy, B.W., Feeney, P.J.: Experimental and computational approaches to estimate solubility and permeability in drug discovery and development settings. Advanced drug delivery reviews 23(1-3), 3–25 (1997)
  28. [28]Hu, E.J., Shen, Y., Wallis, P., Allen-Zhu, Z., Li, Y., Wang, S., Wang, L., Chen, W.: Lora: Low-rank adaptation of large language models. arXiv preprint arXiv:2106.09685 (2021)arxiv.org/abs/2106.09685
  29. [29]Adam, Y., Maxime, R., Xi, W., Laurence, A.: Bayesian Low-rank Adaptation for Large Language Models (2024). https://arxiv.org/abs/2308.13111
  30. [30]Psaros, A.F., Meng, X., Zou, Z., Guo, L., Karniadakis, G.E.: Uncertainty quantification in scientific machine learning: Methods, metrics, and comparisons. Journal of Computational Physics 477, 111902 (2023)DOI
  31. [31]Wang, K., Cuzzolin, F., Shariatmadar, K., Moens, D., Hallez, H.: A review of uncertainty representation and quantification in neural networks. IEEE Transactions on Pattern Analysis and Machine Intelligence 48(3), 2476–2495 (2026)DOI
  32. [32]Izmailov, P., Maddox, W.J., Kirichenko, P., Garipov, T., Vetrov, D., Wilson, A.G.: Subspace inference for Bayesian deep learning. In: Uncertainty in Artificial Intelligence, pp. 1169–1179 (2020). PMLRarxiv.org/abs/1907.07504
  33. [33]Grosse, R., Martens, J.: A kronecker-factored approximate fisher matrix for convolution layers. In: International Conference on Machine Learning, pp. 573–582 (2016). PMLRarxiv.org/abs/1602.01407
  34. [34]Ritter, H., Botev, A., Barber, D.: A scalable Laplace approximation for neural networks. In: International Conference on Learning Representations (2018). https://openreview.net/forum?id=Skdvd2xAZ
  35. [35]Daxberger, E., Kristiadi, A., Immer, A., Eschenhagen, R., Bauer, M., Hennig, P.: Laplace redux-effortless Bayesian deep learning. Advances in neural information processing systems 34, 20089–20103 (2021)arxiv.org/abs/2106.14806
  36. [36]Nafiz, A., Jantre, S., Urban, N.M., Yoon, B.: Leveraging active subspaces to capture epistemic model uncertainty in deep generative models for molecular design. In: 2024 IEEE 34th International Workshop on Machine Learning for Signal Processing (MLSP), pp. 1–6. IEEE, ??? (2024). https://doi.org/10.1109/mlsp58920.2024.10734787 · https://dx.doi.org/10.1109/MLSP58920.2024.10734787
  37. [37]Kunstner, F., Hennig, P., Balles, L.: Limitations of the empirical Fisher approximation for natural gradient descent. Advances in neural information processing systems 32 (2019)arxiv.org/abs/1905.12558
  38. [38]Gur-Ari, G., Roberts, D.A., Dyer, E.: Gradient descent happens in a tiny subspace. arXiv preprint arXiv:1812.04754 (2018)
  39. [39]Chen, T.: The Lanczos algorithm for matrix functions: a handbook for scientists (2026). https://arxiv.org/abs/2410.11090
  40. [40]Lanczos, C.: An iteration method for the solution of the eigenvalue problem of linear differential and integral operators. Journal of research of the National Bureau of Standards 45(4), 255–282 (1950)DOI
  41. [41]Pearlmutter, B.A.: Fast exact multiplication by the Hessian. Neural computation 6(1), 147–160 (1994)DOI
  42. [42]Carlin, B.P., Louis, T.A.: Empirical Bayes: Past, present and future. Journal of the American Statistical Association 95(452), 1286–1289 (2000)DOI
  43. [43]Guo, C., Pleiss, G., Sun, Y., Weinberger, K.Q.: On calibration of modern neural networks. In: International Conference on Machine Learning, pp. 1321–1330 (2017). PMLRarxiv.org/abs/1706.04599

Paper details

vlnc:W_pyuu3bhf
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

GPT-5.5 (bare)

View statement
Looking for related papers…
Contents