Ensemble Kalman filter for uncertainty in human language comprehension Note: The research has been funded by the Deutsche Forschungsgemeinschaft (DFG)- Project-ID 318763901 - SFB1294. Diksha Bhandari, Alessandro Lopopolo, Milena Rabovsky, Sebastian Reich Abstract Artificial neural networks (ANNs) are widely used in modeling sentence processing but often exhibit deterministic behavior, contrasting with human sentence comprehension, which manages uncertainty during ambiguous or unexpected inputs. This is exemplified by reversal anomalies—sentences with unexpected role reversals that challenge syntax and semantics—highlighting the limitations of traditional ANN models, such as the Sentence Gestalt (SG) Model. To address these limitations, we propose a Bayesian framework for sentence comprehension, applying an extention of the ensemble Kalman filter (EnKF) for Bayesian inference to quantify uncertainty. By framing language comprehension as a Bayesian inverse problem, this approach enhances the SG model’s ability to reflect human sentence processing with respect to the representation of uncertainty. Numerical experiments and comparisons with maximum likelihood estimation (MLE) demonstrate that Bayesian methods improve uncertainty representation, enabling the model to better approximate human cognitive processing when dealing with linguistic ambiguities. Journal: Journal of Mathematical Psychology 1 Introduction Artificial neural networks (ANNs) have become indispensable tools in modeling sentence processing within the field of natural language processing and cognitive science. These models are capable of handling complex linguistic structures, making accurate predictions, and resolving ambiguities with a notable degree of certainty, even when they are wrong Guo et al. (2017) ; Hein et al. (2019) . However, this behavior stands in contrast to human sentence comprehension, which often involves managing uncertainty, especially when faced with ambiguous or unexpected language inputs. Human cognition frequently engages in reanalysis, revisions, and flexible interpretations during sentence processing, highlighting a potential mismatch between the deterministic behavior of ANNs and the more adaptive nature of human understanding, which is - among other things - based on representing uncertainty in case of conflicting cues. This paper addresses the disparity between ANNs and human cognition in processing uncertainty during sentence comprehension, with a particular focus on reversal anomalies – sentences that disrupt expected meaning patterns. For instance, in a sentence such as “The dog was bitten by the man" (example 1; Ferreira (2003) ) or “Every morning at breakfast the eggs would eat…." (example 2; Kuperberg et al. (2003) ), typical agent and patient roles are reversed. Reversal anomalies present a significant challenge to both human and artificial systems by introducing conflicts between syntax and semantics that can lead to comprehension breakdowns or reinterpretations. While ANNs such as the Sentence Gestalt Model McClelland et al. (1989) ; St. John and McClelland (1990) ; Rabovsky et al. (2018) , can display a high level of certainty even during misinterpretations, human behavioral performance in sentence processing often displays higher levels of uncertainty Ferreira (2003) . To explore this disparity and work towards reducing it, we examine the performance of the Sentence Gestalt Model, an ANN-based model of sentence comprehension, when confronted with reversal anomalies, and compare its handling of uncertainty to a Bayesian approach that is meant to enhance the model’s ability to account for uncertainty, which is often overlooked in traditional deep learning models of language processing. In this work, we investigate a sampling method based on an extension of the ensemble Kalman filter (EnKF) for uncertainty quantification. By formulating the task of language comprehension as a Bayesian inverse problem, we aim to improve the model’s capacity to reflect the probabilistic nature of human sentence comprehension and resulting uncertainties. This approach is validated through numerical experiments and a comparison with traditional maximum likelihood estimation (MLE)-based methods. Our results demonstrate that incorporating Bayesian techniques can lead to an enhanced representation of uncertainty in the model when processing ambiguous or conflicting sentence structures, which comes somewhat closer to human cognitive processing of uncertainty. 1.1 Uncertainty in human language comprehension Humans, during sentence comprehension, often adopt heuristic strategies to cope with the complexity of language. These strategies enable individuals to generate a good enough interpretation of a sentence without engaging in a detailed syntactic analysis. Ferreira (2003) suggested that such heuristic approaches prioritize resource efficiency and speed over thoroughness, allowing for rapid comprehension at the expense of occasional misinterpretations, particularly in complex or non-canonical sentences. These heuristic strategies are reflected in increased behavioral uncertainty, which is measurable through higher error rates and longer reaction times when processing non-canonical sentences, such as reversal anomalies (RA). When confronted with such sentences that involve conflicts between syntactic structure (which would suggest that the man bites the dog in example 1, above) and plausibility (which would suggest that it should be rather the dog who bites the man), participants are more prone to errors, suggesting that their reliance on heuristic processing is insufficient for correctly interpreting the sentence structure. Specifically, Ferreira (2003) reported that about 25 percent of college students misinterpreted simple passive sentences such as example 1 above as indicating that the dog was biting the man, which is incompatible with the sentence’s syntax. RA sentences can be interpreted by relying on either syntactic cues or semantic cues. While syntactic analysis would correctly assign the roles based on sentence structure, semantic cues, such as world knowledge or expectations about event probabilities, often guide interpretation. In RA sentences, humans frequently default to semantic cues, leading to misinterpretations where the brain gravitates toward a more plausible event scenario rather than adhering strictly to syntactic rules as explained for the example above. This tendency can lead to so called good-enough processing and misinterpretations Ferreira (2003) and can create what is known in event related potential (ERP) research as a semantic illusion, where the sentence initially seems to make sense based on real-world knowledge (leading to small amplitudes of the N400 ERP component, which is usually large for semantic anomalies, Kutas and Federmeier (2011) ), but later requires reanalysis due to its syntactic inconsistency (reflected in large amplitudes of the subsequent P600 component), Kuperberg et al. (2003) . While humans display a high level of uncertainty when interpreting RA sentences due to the conflicting cues, computational models of language processing, such as the SG model originally proposed by St. John and McClelland (1990) and extended by Rabovsky et al. (2018) to account for N400 amplitudes, can exhibit high confidence in their interpretation by consistently favoring semantic cue-based processing of reversal anomalies. In the SG model, the word “eggs” in example 2, above, was consistently and confidently interpreted as the patient rather than the agent, reflecting a plausibility-based interpretation that aligns with expected event structures. This confident misinterpretation was likely due to the fact that the SG model had never experienced the eggs as the agents of an eating action during training. Nonetheless, the mismatch with the syntactic structure of the sentence could have been expected to introduce some hints of doubt within the system. The SG model’s strong and confident reliance on event probabilities despite conflicting cues underscores how computational systems can be highly confident even when they are wrong, while in human processing conflicting cues often lead not only to higher error rates but at the same time to greater uncertainty. 1.2 Uncertainty quantification in artificial neural networks Most ANNs and models in deep learning can be viewed as deterministic functions, providing point estimates of model parameters and predictions. While deep learning models are renowned for their strong generalization capabilities, the growing reliance on these models in modern artificial intelligence applications necessitates not only good generalization but also the ability to recognize when they do not know something Gal (2016) . As shown in Guo et al. (2017) ; Hein et al. (2019) , neural networks when fitted by approximating the maximum likelihood estimator (MLE), or, equivalently, minimizing the negative log-likelihood, are not robust to out-of-distribution (OOD) datasets, and do not provide any measure of uncertainty in the model’s predictions. In contrast, a Bayesian approach to ANNs enables uncertainty estimates, allowing confidence levels to be assigned to model predictions. To address the need for uncertainty quantification in ANNs, use of Bayesian neural networks has been introduced in Gal (2016) ; Neal (2011) ; Neal (2012) ; Gal and Ghahramani (2016) . In the case of supervised learning, given a set of training inputs and corresponding output labels \mathcal{D}=\{x_{i},t_{i}\}^{N}_{i=1} , Bayesian inference aims to find the parameters \theta that are likely to have generated the given outputs. Following the Bayesian perspective, we put a prior distribution \pi(\theta) over the parameter space, which represents our belief as to which parameters are likely to have generated our output before our model observes any training data. As the model observes more and more data, it refines the prior distribution to learn the posterior distribution. In an attempt to make the techniques of Bayesian inference in deep learning feasible, methods of “partially” Bayesian neural networks have also been studied in Daxberger et al. (2021) ; Kristiadi et al. (2020) . The EnKF Evensen (2006) , has been a popular choice for performing data assimilation due to its robustness, and ability to handle large-scale and complex dynamical systems. More recently, the EnKF and ensemble Kalman inversion (EKI), have been used as a derivative-free technique for Bayesian inference Haber et al. (2018) ; Kovachki and Stuart (2019) in neural networks. The EnKF has also been studied as a sampling method for Bayesian inverse problems, focusing on the l_{2} -loss function in Ding and Li (2021) . Such methods transform the prior distribution at \tau=0 to samples from the posterior distribution as \tau\rightarrow\infty . The work Bhandari et al. (2024) ; Pidstrigach and Reich (2022) investigates ensemble transform methods for Bayesian inference in logistic regression, i.e., the case of cross-entropy loss function, within the interactive particle setting. 1.3 Sentence Gestalt Model The Sentence Gestalt Model McClelland et al. (1989) ; St. John and McClelland (1990) aims to model the probabilistic aspects of language comprehension by employing a fully connected neural network architecture Rabovsky et al. (2018) . The design of the SG model is based on the principle that listeners dynamically update their probabilistic representation of the described event with each incoming word of the sentence. The model is divided into two components: the update network and the query network. The update network functions as a sequential encoder, processing each linguistic constituent in sequence to generate a “sentence gestalt", which reflects the evolving interpretation of the sentence’s meaning. A recurrent layer in the architecture feeds the output from one iteration as input to the next. Each constituent is encoded as an activation pattern over the constituent units, and the gestalt layer captures the model’s best current guess of the sentence’s meaning. The query network then utilizes this sentence gestalt representation. To decode a specific role-filler pair, the gestalt layer is probed with either the role or filler. The resulting activation from the probe combines with the sentence gestalt in a second hidden layer, producing the activation of the corresponding role-filler pair in the output layer. The architecture of the SGM is illustrated in Figure 1 . In this study, we compare a standard SG model with its Bayesian implementation to examine whether the latter improves the model’s ability to represent uncertainty. Figure 1 : The Sentence Gestalt model The structure of this paper is as follows. Section 2 provides the necessary mathematical background on ensemble transform methods for Bayesian inference in logistic regression. Additionally, it details the formulation and implementation of the proposed sampling method for a Bayesian Sentence Gestalt model, incorporating dropout techniques and an efficient time-stepping scheme. We present and evaluate numerical results comparing the proposed Bayesian SG model with its standard maximum likelihood estimation (MLE)-based implementation in Section 3 . Section 4 offers a discussion of the findings, and concludes with a summary and final remarks. 2 Materials and methods As discussed in Section 1.2 , an MLE training scheme is not robust to out-of-distribution (OOD) dataset, and does not provide any measure of uncertainty in the model’s predictions. To overcome this problem, we propose a Bayesian inference approach by replacing the point estimator \hat{\theta} with a posterior distribution \pi(\theta) over the model parameters. Adopting a Bayesian approach, we place a prior distribution \pi_{\text{prior}}(\theta) on the output layer parameters and refine it with data to learn the posterior distribution \pi_{\text{post}} . Using Bayes’ theorem, the posterior distribution is given by \pi_{\text{post}}(\theta)\propto\exp(-l(\theta))\,\pi_{\text{prior}}(\theta), (1) where l(\theta) denotes the negative log-likelihood function. Consider the data set \mathcal{D}=\{(\psi^{n},t^{n})\}_{n=1}^{N}, where t^{n} are targets for the binary classification with input features \psi^{n}\in\mathbb{R}^{D}\text{ for }n=1,...,N . The \psi^{n} ’s can either be the representation of the data (x^{n},t^{n}) in any numerical form, or stem from a feature map. In this work, we will train the SGM with MLE approach for use as a feature map in Bayesian inference. We decompose the r -layered SGM into a feature map \psi_{\hat{\theta}}:\mathbb{R}^{n}\rightarrow\mathbb{R}^{d} , representing the first r-1 layers, and an output layer. The output layer is expressed as: F_{\tilde{\theta}}(x)=\sigma(\langle\theta,\psi_{\hat{\theta}}(x)\rangle), (2) where \tilde{\theta}=(\hat{\theta}^{\rm T},\theta^{\rm T})^{\rm T} . We first train the entire network using an MLE approach to obtain \tilde{\theta}_{\text{MLE}} and the trained feature map \psi(x)=\psi_{\hat{\theta}_{\text{MLE}}}(x) . Figure 2 : Last-layer Bayesian inference in SGM using ensemble transform methods So, after observing data \mathcal{D} , the goal is to infer \pi(\theta|\mathcal{D}) using Bayes’ formula ( 1 ). The predictive distribution in the case of binary classification is given by \pi(t=1|x,\mathcal{D})=\int\sigma(F_{\theta}(x)\pi(\theta|\mathcal{D})\rm d\theta, (3) where \sigma is the sigmoid function, defined as \sigma(a)=\frac{1}{1+\exp(-a)}. (4) Since, the above integral ( 3 ) is intractable, we use the ensemble of particles distributed according to \pi_{\text{post}} , approximated with an EnKF-based method of Bayesian inference to estimate the predictive distribution as \pi(t=1|x,\mathcal{D})=\frac{1}{J}\sum_{j=1}^{J}\sigma(\langle\theta_{j}^{*},\psi_{\hat{\theta}_{\text{MLE}}}(x)\rangle), (5) where \{\theta_{j}^{*}\}_{j=1}^{J} represents the final ensemble of particles. Figure 2 illustrates the implementation of a last-layer Bayesian inference in the SGM using EnKF-based methods. In the forthcoming sections, we describe an ensemble transform method to infer \theta_{j}^{*} , such that the predictive distribution ( 3 ) can be approximated by ( 5 ) in a tractable and efficient manner. 2.1 Ensemble transform methods for Bayesian logistic regression For binary classification, we consider the dataset \mathcal{D}=\{(\psi^{n},t^{n})\}_{n=1}^{N} , where \psi^{n}\in\mathbb{R}^{D} are input features, and t^{n}\in\{0,1\} are binary targets. The probability of class membership is given by P_{\theta}[\psi\in C_{1}]:=y_{n}(\theta)=\sigma(\langle\theta,\psi\rangle), (6) where \sigma is the sigmoid function defined in ( 4 ), and \langle\cdot,\cdot\rangle is the inner product between two vectors. Further, we introduce the notation \Psi=(\psi^{1},...,\psi^{N})\in\mathbb{R}^{\mathit{D\times N}}. The negative log-likelihood is given by cross entropy loss function l(\theta)=-\sum_{n=1}^{N}\left(t_{n}\log(y_{n}(\theta))+(1-t_{n})\log(1-y_{n}(\theta))\right). (7) The gradient of the negative log-likelihood l is given by \nabla_{\theta}l(\theta)=\sum_{n=1}^{N}(y_{n}(\theta)-t^{n})\psi^{n}=\Psi(y(\theta)-t), (8) and the Hessian is D_{\theta}^{2}l(\theta)=\Psi R(\theta)\Psi^{\rm T}. (9) Here R(\theta)\in\mathbb{R}^{N\times N} is a diagonal matrix with diagonal entries r_{nn}=y_{n}(\theta)(1-y_{n}(\theta)). We denote by \theta^{1}_{\tau},\ldots\theta^{J}_{\tau} an ensemble of J particles, indexed by a time parameter \tau\geq 0 . We denote by m_{\theta_{\tau}} the empirical mean of the ensemble, m_{\theta_{\tau}}=\frac{1}{J}\sum_{j=1}^{J}\theta_{\tau}^{j}, (10) and by P_{\theta_{\tau}} the empirical covariance matrix, P_{\theta_{\tau}}=\frac{1}{J-1}\sum_{j=1}^{J}(\theta_{\tau}^{j}-m_{\tau})(\theta_{\tau}^{j}-m_{\tau})^{\rm T}. (11) We introduce the matrix of ensemble deviations \Theta_{s}\in\mathbb{R}^{D\times J} as \Theta_{\tau}=\left(\theta_{\tau}^{1}-m_{\theta_{\tau}},\theta_{\tau}^{2}-m_{\theta_{\tau}},\ldots,\theta_{\tau}^{J}-m_{\theta_{\tau}}\right). (12) We will adapt the convention that upper indices stand for the ensemble index, while lower indices stand for the time index or the i th entry of an N -dimensional vector. Associated to the particle system is the empirical measure \mu_{\theta_{\tau}}=\frac{1}{J}\sum_{j=1}^{J}\delta_{\theta^{j}_{\tau}}, where \delta_{\theta} stands for the Dirac delta at \theta . We denote the expectation with respect to this measure by \mu_{\theta_{\tau}}[g] , i.e. for a function g , \mu_{\theta_{\tau}}[g]=\frac{1}{J}\sum_{j=1}^{J}g(\theta^{j}_{\tau}). In the following subsection, we briefly describe the dynamical system formulation of an ensemble transform method for Bayesian inference in a logistic regression problem. For further details on the derivation of the method, refer Bhandari et al. (2024) . 2.1.1 Dropout deterministic sampler The dropout deterministic sampler presented in this section operates by simulating a dynamical system where an ensemble of parameters \{\theta_{\tau}^{j}\}_{j=1}^{J} evolves over time (\tau\geq 0) according to an evolution equation described by an interacting particle system (IPS) ODE. Starting from the initial ensemble \{\theta_{0}^{j}\}_{j=1}^{J}\sim\pi_{\rm prior} , the IPS is structured to harness the evolution of the empirical mean and covariance, guiding the ensemble towards regions of high posterior probability, as the model sees more and more data. The system then samples from the target distribution in the limit \tau\to\infty . The key idea of the deterministic (second-order) sampler introduced in Bhandari et al. (2024) is to combine the homotopy approach Pidstrigach and Reich (2022) with a deterministic equivalent of overdamped Langevin dynamics to motivate an IPS that approximates the posterior. Therefore, one can construct systems that sample the target distribution as \tau\to\infty , a property of the most famously used Markov Chain Monte Carlo (MCMC) algorithms. However, the computational complexity of these MCMC methods makes them impractical to use in Bayesian inference for large ANNs. Thus, to make the Bayesian approach feasible, we use the deterministic second-order sampler introduced in Bhandari et al. (2024) , which has been shown to demonstrate similar uncertainty estimates as the Hamiltonian Monte Carlo (HMC) method. The advantage of using the deterministic sampler is that it has been experimentally shown to have faster convergence towards equilibrium than HMC, and the particles stop moving once they reach equilibrium. Moreover, under appropriate conditions, the determinsitic sampler gives an exact representation for the evolution of mean m_{\theta_{\tau}} and covariance P_{\theta_{\tau}} in the limit \tau\rightarrow\infty . The IPS ODE we will use is given by \begin{split}\frac{\mathrm{d}\theta_{\tau}^{j}}{\mathrm{d}\tau}&=-\frac{1}{2}P_{\theta_{\tau}}\Psi\Bigl(\mu_{\theta_{\tau}}[R]\Psi^{\rm T}(\theta_{\tau}^{j}-m_{\theta_{\tau}})+2(\mu_{\theta_{\tau}}[y]-t)\Bigr)\\ &\qquad-\,\frac{1}{2}P_{\theta_{\tau}}P_{\rm{prior}}^{-1}(\theta^{j}_{\tau}+m_{\theta_{\tau}}-2m_{\rm{prior}})+\frac{1}{2}(\theta^{j}_{\tau}-m_{\theta_{\tau}})\end{split} (13) with random initial conditions \theta^{j}_{0}\sim\mathcal{N}(m_{\rm{prior}},P_{\rm{prior}}) i.i.d. for j=1,\ldots,J . In Section 2.2 , we describe the dropout technique and linearly implicit, efficient methods of time-stepping, used in combination with the deterministic sampler for robust numerical implementation. 2.2 Dropout and time-stepping For ensemble sizes K\leq J , the ensemble \{\theta_{\tau}^{j}\}_{j=1}^{K} tends to propagate in the subspace defined by the initial ensemble parameters. To overcome this, we use ensemble dropout, where a fraction \rho\in(0,1) of the entries in \{\theta_{\tau}^{j}\},j=1...,K are randomly set to zero. The dropout technique, first introduced for neural networks in Srivastava et al. (2014) , can be viewed as an implicit regularization method to avoid overfitting during training. For high dimensional Bayesian logistic regression problems, the dropout in our ensemble transform method can be intercepted as a similar technique to avoid spurious correlations, and break the “subspace property" in the small ensemble size setting Pidstrigach and Reich (2022) . Thus, the empirical covariance matrix is modified as \hat{P}_{\theta_{\tau}}=\frac{1}{(1-\rho)(J-1)}\hat{\Theta}_{\tau}\hat{\Theta}_{\tau}^{\rm T}, (14) where \hat{\Theta}_{s} represents the ensemble deviations ( 12 ) after dropout. Now, we introduce a step-size \Delta\tau\geq 0 and discrete times {\tau}_{s}=s\Delta\tau . In this section, we will use the shorthand \theta_{\tau_{s}}\approx\theta_{s},m_{\theta_{\tau_{s}}}\approx m_{s},P_{\theta_{\tau_{s}}}\approx P_{s},\Theta_{\tau_{s}}\approx\Theta_{s},\mu_{\theta_{\tau_{s}}}\approx\mu_{s} . We use a Trotter splitting approach to numerically solve ( 13 ), for details see ( Bhandari et al., 2024 , Section 4.2) . Therefore, for every time step s , given \{\theta_{s}^{j}\}_{j=1}^{J} , we compute \theta_{s+1/2}^{j} using the homotopy-based moment matching, with a tamed method of discretization given by \theta_{s+1/2}^{j}=\theta_{s}^{j}-\frac{\Delta\tau}{2}\hat{P}_{s}\Psi\left(M_{s}\Psi^{\rm T}(\theta_{s}^{j}-m_{s})+2(\mu_{s}[y]-t)\right) (15) where \hat{P}_{s} is the dropout empirical covariance matrix defined in ( 14 ), and M_{s}=\left(\Delta\tau\Psi^{\rm T}\hat{P}_{s}\Psi+\mu_{s}[R]\right)^{-1} (16) for j=1,\ldots,J . For the second half step, we apply the following discretization scheme \begin{split}\theta_{s+1}^{j}&=\theta_{s+1/2}^{j}-\frac{\Delta\tau}{2}\hat{P}_{s+1/2}\left(\Delta\tau\hat{P}_{s+1/2}+P_{\rm{prior}}\right)^{-1}(\theta_{s+1/2}^{j}+m_{s+1/2}-2m_{\rm{prior}})\\ &\quad+\frac{\Delta\tau}{2}(\theta^{j}_{s+1/2}-m_{s+1/2}).\end{split} (17) Note that, since P_{\rm prior} is diagonal, full matrix inversion in ( 17 ) is replaced by inverting the diagonal only. We provide a pseudo-code describing the algorithm for dropout deterministic sampler in Algorithm 2.2 . Algorithm 1: Dropout deterministic sampler for Bayesian inference in SG Model Inputs : Data set \{(\psi^{n},t^{n})\}_{n=1}^{N} ; feature map \Psi=\{\psi^{n}\}_{n=1}^{N} ; initial ensemble \{\theta_{0}^{j}\}_{j=1}^{J} ; dropout rate \rho ; step-size \Delta\tau ; threshold value \epsilon>0 . Initialize : s=0 . while \frac{\|\hat{P}_{s+1}-\hat{P}_{s}\|_{2}}{\|\hat{P}_{s}\|_{2}}\geq\epsilon do: 1. Numerically solve ODE ( 13 ) by trotter splitting: (a) Compute ensemble mean m_{s} ( 10 ), dropout ensemble deviations \hat{\Theta}_{s} , and dropout covariance \hat{P}_{s} ( 14 ). (b) Evaluate y ( 6 ), \mu_{s}[y] , \mu_{s}[R] and M_{s} ( 16 ). (c) Determine \{\theta^{j}_{s+1/2}\}_{j=1}^{J} by evolving \theta_{s+1/2} using the time-stepping ( 15 ). (d) Evaluate dropout covariance matrix \hat{P}_{s+1/2} ( 14 ). (e) Determine \{\theta^{j}_{s+1}\}_{j=1}^{J} using the time-stepping ( 17 ). 2. Update the ensemble \{\theta_{s}^{j}\}_{j=1}^{J}\rightarrow\{\theta_{s+1}^{j}\}_{j=1}^{J} . Increment s . end while Output: Final ensemble \{\theta^{j}_{s}\}_{j=1}^{J} . 2.3 Training corpus Model training and parameter estimation were performed on a synthetically generated corpus consisting of N=10,000 sentences made of 3-5 words. Similar to a previous implementation Rabovsky et al. (2018) , events are described in terms of an action, an agent, a location, a situation, and a patient or object onto which the action is performed, and were composed of active transitive structures. The corpus contained 72 unique tokens (see A for a complete list of words that form the input constituents) , representing a diverse set of concrete nouns and action verbs. The corpus consists of 12 actions, one out of which was randomly chosen with equal probability. Then, an appropriate agent out of the 4 possible options (man, woman, boy, and girl with different probabilities) was chosen to perform the activated action. This was followed by choosing a suitable situation for the action. An action can occur without any situation, some actions in one, and some with two possible situations. Then, depending on the action, a patient (out of the 36 objects) was selected. Depending on the action and situation, a location may or may not be present in the sentence. Thus, possible sentence structures are: (i) for sentences with situation, [situation][agent][action][patient][location], and (ii) for sentences without situation, [agent][action][patient][location, if any]. Each word in the corpus was encoded using 176 binary semantic features, hand-coded to capture key semantic properties. As described above, binary semantic features were used as filler-concept representation and therefore presented to the model as probe (to the probe layer) and target (to the output layer) during training. Table 2 shows an example of words and their semantic representations used to construct the training environment for the SG model. Words Semantic representations woman agent, adult, female, woman eat action, consume, done with foods, eat kitchen location, inside, place to eat, kitchen breakfast situation, food related, in the morning, breakfast egg consumable, food, white, egg during/at no output units (activated together with situation words, e.g., “at breakfast") Table 2 : Sample words (inputs) and their semantic representations (probes and outputs). 2.4 Model training with maximum likelihood estimation The input dataset comprises a randomly sampled training input of (constituent, probe) pairs described above, denoted by x_{n}=(i_{n},p_{n}),n=1,\dots,N , as a combined sequential input data. The target (output) labels are possible responses to probes being 1 (if the feature is present) or 0 (if the feature is not present). A fully-connected layer followed by a sigmoid activation function is applied to the output of the neural network and the result is compared to the given target labels using a cross entropy loss function. We first train the complete SG model F_{\theta}(x) with a regularized MLE technique, using ADAM optimizer with a learning rate of 4\times 10^{-3} and weight decay for optimization. The model is run for 60 epochs using cross validation and an “early stopping" criteria with a goal of monitored training to minimize the cross entropy loss and avoid overfitting during training. The MLE approach minimizes the cross entropy loss ( 7 ) across the training set, which provides the minimizer \theta_{\text{MLE}} and an associated feature map \psi(x):=\psi_{\theta_{\text{MLE}}}(x) . 2.5 Experimental conditions We performed two types of analyses on each comparison: a model analysis and an item analysis, both evaluated using a set of eight semantically congruent (canonical) sentences, each paired with its corresponding reversal anomaly (RA) version based on ten runs of the model. In the congruent sentences, the scenarios depicted plausible agents performing typical actions relevant to the context (e.g., “During dinner, the woman eats \dots "). For the reversal anomalies, each scenario was modified by replacing the agent with a high-probability patient related to the context, followed by an action normally associated with the agent (e.g., “During dinner, the pizza eats \dots "). A model analysis was performed using output values averaged over items within each version for m=10 models with different random initializations. An item analysis was performed with values averaged over models and for each item ( n=8 items). 3 Results In this section, we present numerical and statistical results for output activations of the SG model, when trained with standard MLE estimates, and Bayesian approximation with the proposed EnKF-based dropout deterministic sampler 2.2 . The training set \{(x^{n},t^{n})\}_{n=1}^{N} consists of sentences and queries about the events the sentences describe (inputs) so that it can provide responses (labels) to such queries. We train the complete SG model using a regularized MLE technique as described in Section 2.4 . The model has a test accuracy of 97.84\% . Figure 3 shows the plots for model loss and accuracy during train and test phases. (a) ADAM train and test loss (b) ADAM train and test accuracy Figure 3 : Training & test loss and accuracy obtained by training SGM with ADAM optimizer. Training using the MLE approach provides the minimizer \theta_{\text{MLE}} and an associated feature map \psi_{\text{MLE}}(x) . This feature map \psi_{\text{MLE}}(x) is used for Bayesian logistic regression over multiple output features. We implement the proposed dropout deterministic sampler for Bayesian inference using a Gaussian prior with mean m_{\text{prior}}=\theta_{\text{MLE}} and covariance matrix P_{\text{prior}}=I . The results reported in this section are obtained using a dropout rate \rho=0.3 and \tau=17 discrete time-steps. We use the final ensemble of particles \{\theta^{j}_{\ast}\}_{j=1}^{J} distributed according to \pi_{\text{post}}(\theta) , approximated with the proposed sampler to estimate the predictive distribution as described in ( 5 ). 3.1 Processing congruent and reversal anomaly sentences In this experiment, we report the activation of selected output units when the model is presented with test sentences consisting of semantically congruent and their correspondent RA versions. For both cases, we examine the mean activations of the selected output units across all test sentences ( n=8 items) and compare the probability of feature activation using the MLE-trained and the Bayesian SG model. We report and compare the the mean activations of the output units for congruent form of test sentences using the ADAM-trained SG model and the Bayesian SG model in Figure 4 . Additionally, mean activations for RA test sentences are shown in Figure 5 . Mean activations obtained after each word in the test sentences is presented to the model are provided in the Appendix, with details on processing of congruent and RA sentences using the ADAM-trained SG model shown in Figures 6 and 8 , respectively. As shown in Figure 4 , the MLE-trained SG model exhibits high mean output activations for semantically plausible agents and patients in congruent sentences. For instance, the model strongly activates “woman" when probed for the agent and “pizza" when probed for the patient in the sentence. When presented with the RA versions of these test sentences, as illustrated in Figure 5 , the MLE-trained model maintains high mean output activations for semantically plausible agents and patients. For example, the model continues to output “woman" as the agent and “pizza" as the patient in RA sentences, demonstrating a strong reliance on semantic cues even in reversal anomaly contexts. The performance of the Bayesian SG model, implemented using the dropout deterministic sampler, was compared to the traditional MLE-trained SG model. As shown in Figure 4 , the Bayesian SG model achieves comparable mean activations for semantically plausible agents and patients in congruent sentences. However, when handling RA sentences, the Bayesian model exhibits greater uncertainty. Specifically, as reported in Figure 5 , the mean activations for semantically plausible agents and patients decrease, along with an increase in the activation of syntactically indicated agents and patients, showing that the model accounts for unusual thematic role assignments in these out-of-distribution (OOD) scenarios, taking into account both semantic and syntactic cues. Refer to Figures 7 and 9 for the mean output activations after each word in the test sentences is input, corresponding to congruent and RA sentences, respectively, using the Bayesian SG model. This behavior highlights the Bayesian model’s enhanced uncertainty to the ambiguity in RA test cases compared to the traditional MLE approach. “During dinner, woman eats pizza” Figure 4 : Mean activations (with standard deviations) of selected output units for the congruent form of test sentences using the ADAM-trained SG model and the Bayesian SG model (with dropout deterministic sampler). Blue bars indicate the output activations of the selected feature (word) from the ADAM-trained model, while red bars represent the predicted probability of the feature being activated in the Bayesian SG model. Black error bars denote standard deviations. “During dinner, pizza eats woman” Figure 5 : Mean activations (with standard deviations) of selected output units for the RA form of test sentences using the ADAM-trained SG model and the Bayesian SG model (with dropout deterministic sampler). Blue bars indicate the output activations of the selected feature (word) from the ADAM-trained model, while red bars represent the predicted probability of the feature being activated in the Bayesian SG model. Black error bars denote standard deviations. 3.2 Statistical analysis of reversal anomaly sentences To quantitatively compare the predictive performance of the SG model trained using the MLE approach and the last-layer Bayesian approximation with the dropout deterministic sampler, we conducted a series of statistical tests. As described in Section 2.5 , both model-level and item-level analyses were performed on the RA test sentences. First, a one-sample t-test was conducted to determine whether the mean activations for reversed words (e.g., “pizza as agent" and “woman as patient") across 10 runs of the MLE-trained SG model (ADAM) significantly differed from zero (model analysis). Additionally, an item-level analysis was conducted for n=8 items. The null hypothesis in both tests was that there is no significant difference between the mean activation and zero. Table 3 summarizes the p-value results from the t-tests for model analysis. Word Role Probe ADAM Dropout deterministic sampler Syntactically indicated agents Agent 0.9153 <0.0001 Semantically plausible agents Patient 0.9029 <0.0001 All non-relevant patients Agent 0.8691 0.6642 Table 3 : Comparison of p-values from t-tests against zero for SG model output activations on RA test sentences, using ADAM and the dropout deterministic sampler (model analysis). Activations obtained with ADAM show no significant deviation from zero ( p>0.05 ), whereas those from the dropout sampler exhibit a significant difference from zero ( p<0.05 ) across reversed words. The results indicate that, for the ADAM-trained SG model, activations across all reversed words do not differ significantly from zero ( p>0.05 ), implying that the mean activations are close to zero relative to sample variability. In contrast, the Bayesian SG model employing the dropout deterministic sampler exhibits significant difference from zero ( p<0.05 ) for reversed words (”pizza as agent" and ”woman as patient"). However, for non-relevant patients (e.g., ”chess as agent"), results indicate no significant difference from zero ( p>0.05 ). This additional test for non-relevant patients is meant to demonstrate that the non-zero activations were not due to higher noise, but instead reflected meaningful activations in response to the uncertainty induced by the conflict between semantic and syntactic cues. Results from the item-level t-tests against zero, for both ADAM-trained and the Bayesian SG model with the dropout deterministic sampler are provided in Table 6 . Further, we conducted paired t-tests to compare the activations from the dropout deterministic sampler with those from the ADAM-trained SG model. Word Role Probe t-statistic p-value Syntactically indicated agents Agent 4.6858 <0.0001 Semantically plausible agents Patient 6.1014 <0.0001 All non-relevant patients Agent -5.4184 <0.0001 Table 4 : Paired t-test comparing output activations from the dropout deterministic sampler and the ADAM-trained SG model on RA test sentences (model analysis). Results show significant differences in mean activations ( p<0.001 ), with positive t-statistics for reversed words indicating greater uncertainty in the Bayesian SG model compared to the ADAM-trained model. The results of the paired t-tests for model analysis, as summarized in Table 4 , show a significant difference in mean activations across both reversed words and all non-relevant patients ( p<0.001 ). Positive t-statistics for reversed words indicate that the Bayesian SG model yields higher mean activations than ADAM trained SG model, reflecting greater uncertainty in handling reversal anomalies. Conversely, the negative t-statistics for non-relevant patients suggest that the Bayesian SG model produces lower mean activations for such words being assigned the role of “agent" compared to the ADAM-trained model. This shows that overall the activations of the Bayesian SG model are more specific. For item analysis, refer to Table 7 . 4 Discussion In this work, we aim to address a key limitation in current artificial neural network (ANN) models of language comprehension: their inability to represent uncertainty in the presence of ambiguous or conflicting cues, such as those found in reversal anomalies (RAs). Traditional models like the Sentence Gestalt (SG) model, when trained with maximum likelihood estimation (MLE), can exhibit overly deterministic behavior—even in scenarios where human sentence processing reflects significant uncertainty Guo et al. (2017) ; Hein et al. (2019) . This stands in contrast to extensive findings in cognitive science showing that human comprehension involves flexible interpretation and often displays uncertainty under non-canonical structures Ferreira (2003) ; Kuperberg et al. (2003) . In accordance with these observations, our comparison of a standard MLE-trained SG model St. John and McClelland (1990) , and a Bayesian version of the model using an ensemble Kalman filter (EnKF)-based sampler Bhandari et al. (2024) , highlights substantial differences in how these approaches deal with semantic and syntactic conflicts. In semantically congruent sentences, both models produced high mean activations for expected agents and patients. However, under RA conditions, the traditional SG model maintained high confidence in semantically plausible but syntactically incorrect role assignments. This indicates a continued reliance on learned event probabilities, failing to reflect the kind of uncertainty that is typically observed in human sentence processing when syntactic and semantic cues are misaligned. In contrast, the Bayesian SG model displayed behavior more consistent with human comprehension. Specifically, it demonstrated reduced activations for semantically plausible but syntactically incorrect role assignments and increased activations for syntactically indicated roles in RA conditions. This shift reflects greater sensitivity to cue conflict and suggests that the model is capable of maintaining uncertainty in cases where the correct interpretation is ambiguous—bringing it closer to the variability and probabilistic nature of human responses Kutas and Federmeier (2011) ; Ferreira (2003) . These results strengthen the argument that incorporating Bayesian inference into ANN models offers a promising route toward addressing a longstanding gap in modeling human language comprehension. By framing language understanding as a Bayesian inverse problem and using EnKF-based sampling methods Bhandari et al. (2024) , we not only obtain better-calibrated predictions but also a model architecture that naturally reflects the uncertainty observed in human behavior. Notably, the Bayesian SG model differentiates between meaningful and irrelevant cues, maintaining low confidence for implausible role assignments while remaining responsive to both semantic and syntactic inputs. In summary, our findings suggest that deterministic ANNs, while powerful, by themselves may not be well-suited to capturing the ambiguity inherent in real-world language comprehension. In contrast, the Bayesian approach introduced in this paper provides a compelling extension by allowing model predictions to reflect degrees of belief rather than point estimates, thereby aligning better with human cognitive processes. Future work can build on this foundation by exploring more complex linguistic structures, incorporating richer semantic environments, or extending Bayesian inference across varying layers of the model architecture. This line of research may help bridge the gap between computational modeling and the probabilistic nature of human sentence understanding. CRediT authorship contribution statement Diksha Bhandari: Writing – original draft, Writing – review & editing, Visualization, Software, Methodology, Investigation, Formal analysis, Data curation, Conceptualization. Alessandro Lopopolo: Writing – original draft, Writing – review & editing, Conceptualization. Milena Rabovsky: Writing – review & editing, Visualization, Supervision, Project administration, Funding acquisition, Conceptualization. Sebastian Reich: Writing – review & editing, Supervision, Project administration, Funding acquisition, Conceptualization. Appendix A Words and their semantic representations Table 5 : Words (input unit labels) and their corresponding semantic representations (output unit labels representing the concepts referred to by the words). Words Semantic representations Woman person, active, adult, female, woman Man person, active, adult, male, man Girl person, active, child, female, girl Boy person, active, child, male, boy Drink action, consume, done with liquids, drink Eat action, consume, done with foods, eat Feed action, done to animals, done with food, feed Fish action, done to fishes, done close to water, fish Plant action, done to plants, done with earth, plant Water action, done to plants, done with water, water Play action, done with games, done for fun, play Wear action, done with clothes, done for warming, wear Read action, done with letters, perceptual, read Write action, done with letters, productive, write Look at action, visual look at Like action, positive, like Kitchen location, inside, place to eat, kitchen Living room location, inside, place for leisure, living room Bedroom location, inside, place to sleep, bedroom Garden location, outside, place for leisure, garden Lake location, outside, place with animals, lake Park location, outside, place with animals, park Balcony location, outside, place to step out, balcony River location, outside, place with water, river Backyard location, outside, place behind house, backyard Veranda location, outside, place in front of house, veranda Breakfast situation, food related, in the morning, breakfast Dinner situation, food related, in the evening, dinner Excursion situation, going somewhere, to enjoy, excursion Afternoon situation, after lunch, day time, afternoon Holiday situation, special day, no work, holiday Sunday situation, free time, to relax, Sunday Morning situation, early, wake up, morning Evening situation, late, get tired, evening Egg consumable, food, white, egg Toast consumable, food, brown, toast Cereals consumable, food, healthy, cereals Soup consumable, food, in bowl, soup Pizza consumable, food, round, pizza Salad consumable, food, light, salad Iced tea consumable, drink, from leaves, iced tea Juice consumable, drink, from fruit, juice Lemonade consumable, drink, sweet, lemonade Cacao consumable, drink, with chocolate, cacao Tea consumable, drink, hot, tea Coffee consumable, drink, activating, coffee Chess game, entertaining, strategic, chess Monopoly game, entertaining, with dice, monopoly Backgammon game, entertaining, old, backgammon Jeans garment, to cover body, for legs, jeans Shirt garment, to cover body, for upper part, shirt Pajamas garment, to cover body, for night, pajamas Novel contains language, contains letters, art, novel Email contains language, contains letters, communication, email SMS contains language, contains letters, communication, short, SMS Letter contains language, contains letters, communication, on paper, letter Paper contains language, contains letters, scientific, paper Newspaper contains language, contains letters, information, newspaper Rose can grow, has roots, has petals, red, rose Daisy can grow, has roots, has petals, yellow, daisy Tulip can grow, has roots, has petals, colorful, tulip Pine can grow, has roots, has bark, green, pine Oak can grow, has roots, has bark, tall, oak Birch can grow, has roots, has bark, white bark, birch Robin can grow, can move, can fly, red, robin Canary can grow, can move, can fly, yellow, canary Sparrow can grow, can move, can fly, brown, sparrow Sunfish can grow, can move, can swim, yellow, sunfish Salmon can grow, can move, can swim, red, salmon Eel can grow, can move, can swim, long, eel During/at no output units (activated together with situation words, e.g., “at breakfast") In no output units (activated together with location words, e.g., “in the park") Appendix B Output activations for congruent and reversal anomaly test sentences “During dinner…” “…woman…” “…eats…” “…pizza” Figure 6 : ADAM trained SGM: mean activations (with standard deviations) of selected output units for congruent form of test sentences. “During dinner…” “…woman…” “…eats…” “…pizza” Figure 7 : Dropout deterministic sampler for SGM: mean activations (with standard deviations) of selected output units for congruent form of test sentences. “During dinner…” “…pizza…” “…eats…” “…woman” Figure 8 : ADAM trained SGM: mean activations (with standard deviations) of selected output units for RA form of test sentences. Note that the model continues to represent the pizza as the patient (and not the agent) of eating, even after the word “eat” has been presented as input in the sentence. “During dinner…” “…pizza…” “…eats…” “…woman” Figure 9 : Dropout deterministic sampler for SGM: mean activations (with standard deviations) of selected output units for RA form of test sentences. Note that the model shows uncertainty while representing pizza (and woman) as the agent (and the patient) of eating, after the word “eat” has been presented as input in the sentence. Appendix C Statistical (item) analysis of reversal anomaly sentences Table 6 summarizes the results of the one-sample t-tests against zero, conducted for item analysis ( n=8 items). Word Role Probe ADAM Dropout deterministic sampler Syntactically indicated agents Agent 0.8890 <0.0001 Semantically plausible agents Patient 0.8606 <0.0001 All non-relevant patients Agent 0.8906 0.7140 Table 6 : Comparison of p-values from t-tests against zero for SGM output activations obtained using ADAM and the dropout deterministic sampler on RA test sentences (item analysis). The results show no significant deviation from zero for ADAM ( p>.05 ), while the dropout sampler shows significant differences from zero for activations across reversed words ( p<.05 ). Table 7 presents the results of paired t-tests comparing the activations generated by the Bayesian SG model and the ADAM-trained SG model ( n=8 items). Word Role Probe t-statistic p-value Syntactically indicated agents Agent 9.1730 <0.0001 Semantically plausible agents Patient 13.140 <0.0001 All non-relevant patients Agent -9.8349 <0.0001 Table 7 : Paired t-test comparing activations from the dropout deterministic sampler to the ADAM-trained SGM for RA test sentences (item analysis). The results show significant differences in mean activations ( p<.001 ), with positive t-statistics for reversed words indicating higher uncertainty in the Bayesian SGM compared to the ADAM-trained model. Appendix D Effect of modifying prior covariance P_{\text{prior}} We investigate the impact of varying the prior covariance P_{\text{prior}} on model activations, focusing on the behavior of the dropout deterministic sampler in RA test sentences. The experiment evaluates model activations for three different prior covariance P_{\text{prior}} : 0.01\operatorname{I} , \operatorname{I} , and 5\operatorname{I} , where \operatorname{I} is the identity matrix (scaled by different magnitudes). Word Role Probe p-value 0.01\operatorname{I} \operatorname{I} 5\operatorname{I} Syntactically indicated agents Agent 0.2747 <0.001 <0.001 Semantically plausible agents Patient 0.2110 <0.001 <0.001 All non-relevant patients Agent 0.9635 <0.001 <0.001 Table 8 : Paired t-test comparing activations from the ADAM-trained model to those from the dropout deterministic sampler with varying prior covariance values ( P_{\text{prior}}=0.01\operatorname{I},\operatorname{I}, and 5\operatorname{I} ) for RA test sentences (model analysis). The results show no significant difference in mean activations for P_{\text{prior}}=0.01\operatorname{I} ( p>.001 ), while significant differences are observed for larger prior covariances ( p<.001 ). As reported in Table 8 , the difference between output activations obtained with MLE-trained and Bayesian SG model were statistically insignificant ( p>0.001 ) only with a too small prior covariance ( P_{\text{prior}}=0.01\operatorname{I} ), while larger priors ( P_{\text{prior}}=\operatorname{I} and 5\operatorname{I} ) yielded significant differences ( p<0.001 ). It was observed that with a very small prior covariance, the dropout deterministic sampler converged too quickly and was closer to the MLE estimates. In contrast, with a larger prior covariance, the sampler required more time steps to converge to the posterior but provided meaningful uncertainty estimates.