SlowGuess/NeurIPS_2023_OCR huggingface dataset:
A-NESI: A Scalable Approximate Method for Probabilistic Neurosymbolic Inference
Emile van Krieken
Emile.van.Krieken@ed.ac.uk
Jakub M. Tomczak
Thiviyan Thanapalasingam
Frank van Harmelen, Annette ten Teije
We study the problem of combining neural networks with symbolic reasoning. Recently introduced frameworks for Probabilistic Neurosymbolic Learning (PNL), such as DeepProbLog, perform exponential-time exact inference, limiting the scalability of PNL solutions. We introduce Approximate Neurosymbolic Inference (A-NESI): a new framework for PNL that uses neural networks for scalable approximate inference. A-NESI 1) performs approximate inference in polynomial time without changing the semantics of probabilistic logics; 2) is trained using data generated by the background knowledge; 3) can generate symbolic explanations of predictions; and 4) can guarantee the satisfaction of logical constraints at test time, which is vital in safety-critical applications. Our experiments show that A-NESI is the first end-to-end method to solve three neurosymbolic tasks with exponential combinatorial scaling. Finally, our experiments show that A-NESI achieves explainability and safety without a penalty in performance.
Recent work in neurosymbolic learning combines neural perception with symbolic reasoning [52, 38], using symbolic knowledge to constrain the neural network [19], to learn perception from weak supervision signals [36], and to improve data efficiency [5, 57]. Many neurosymbolic methods use a differentiable logic such as fuzzy logics [5, 17] or probabilistic logics [35, 57, 16]. We call the latter Probabilistic Neurosymbolic Learning (PNL) methods. PNL methods add probabilities over discrete truth values to maintain all logical equivalences from classical logic, unlike fuzzy logics [54]. However, performing inference requires solving the weighted model counting (WMC) problem, which is computationally exponential [13], significantly limiting the kind of tasks that PNL can solve.
We study how to scale PNL to exponentially complex tasks using deep generative modelling [51]. Our method called Approximate Neurosymbolic Inference (A-NEsI), introduces two neural networks that perform approximate inference over the WMC problem. The prediction model predicts the output of the system, while the explanation model computes which worlds (i.e. which truth assignment to a set of logical symbols) best explain a prediction. We use a novel training algorithm to fit both models with data generated using background knowledge: A-NEsI samples symbol probabilities from a prior and uses the symbolic background knowledge to compute likely outputs given these probabilities. We train both models on these samples. See Figure 1 for an overview.
A-NESI combines all benefits of neurosymbolic learning with scalability. Our experiments on the Multi-digit MNISTAdd problem [35] show that, unlike other approaches, A-NESI scales almost
Figure 1: Overview of A-NESI. The forward process samples a belief  $\mathbf{P}$  from a prior, then chooses a world  $\mathbf{w}$  for that belief. The symbolic function  $c$  computes its output  $\mathbf{y}$ . The inference model uses the perception model  $f_{\theta}$  to find a belief  $\mathbf{P}$ , then uses the prediction model  $q_{\phi}$  to find the most likely output  $\mathbf{y}$  for that belief. If we also use the optional explanation model, then  $q_{\psi}$  explains the output.
linearly in the number of digits and solves MNISTAdd problems with up to 15 digits while maintaining the predictive performance of exact inference. Furthermore, it can produce explanations of predictions and guarantee the satisfaction of logical constraints using a novel symbolic pruner.
The paper is organized as follows. In Section 3, we introduce A-NESI. Section 3.1 presents scalable neural networks for approximate inference. Section 3.2 outlines a novel training algorithm using data generated by the background knowledge. Section 3.2.4 extends A-NESI to include an explanation model. Section 3.3 extends A-NESI to guarantee the satisfaction of logical formulas. In Section 4, we perform experiments on three Neurosymbolic tasks that require perception and reasoning. Our experiments on Multi-digit MNISTAdd show that A-NESI learns to predict sums of two numbers with 15 handwritten digits, up from 4 in competing systems. Similarly, A-NESI can classify Sudoku puzzles in  $9 \times 9$  grids, up from 4, and find the shortest path in  $30 \times 30$  grids, up from 12.
2 Problem setup
First, we introduce our inference problem. We will use the MNISTAdd task from [35] as a running example. In this problem, we must learn to recognize the sum of two MNIST digits using only the sum as a training label. Importantly, we do not provide the labels of the individual MNIST digits.
2.1 Problem components
We introduce four sets representing the spaces of the variables of interest.
1.  $X$  is an input space. In MNISTAdd, this is the pair of MNIST digits  $\mathbf{x} = (\mathbf{G},\mathbf{G})$ .
2.  $W$  is a structured space of  $k_W$  different discrete variables  $w_i$ , each with their own domain. Its elements  $\mathbf{w} \in W = W_1 \times \ldots \times W_{k_W}$  are worlds or concepts [59] of some  $\mathbf{x} \in X$ . For  $(\mathcal{G}, \mathcal{G})$ , the correct world is  $\mathbf{w} = (5, 8) \in \{0, \ldots, 9\}^2$ .
3.  $Y$  is a structured space of  $k_{Y}$  discrete variables  $y_{i}$ . Elements  $\mathbf{y} \in Y = Y_{1} \times \ldots \times Y_{k_{Y}}$  represent the output of the neurosymbolic system. Given world  $\mathbf{w} = (5,8)$ , the sum is 13. We decompose the sum into individual digits, so  $\mathbf{y} = (1,3) \in \{0,1\} \times \{0,\dots,9\}$ .
4.  $\mathbf{P} \in \Delta^{|W_1|} \times \ldots \times \Delta^{|W_{k_W}|}$ , where each  $\Delta^{|W_i|}$  is the probability simplex over the options of the variable  $w_i$ , is a belief.  $\mathbf{P}$  assigns probabilities to different worlds with  $p(\mathbf{w}|\mathbf{P}) = \prod_{i=1}^{k_W} \mathbf{P}_{i,w_i}$ . That is,  $\mathbf{P}$  is a parameter for an independent categorical distribution over the  $k_W$  choices.
We assume access to some symbolic reasoning function  $c: W \to Y$  that deterministically computes the (structured) output  $\mathbf{y}$  for any world  $\mathbf{w}$ . This function captures our background knowledge of the problem and we do not impose any constraints on its form. For MNISTAdd,  $c$  takes the two digits (5, 8), sums them, and decomposes the sum by digit to form (1, 3).
2.2 Weighted Model Counting
Together, these components form the Weighted Model Counting (WMC) problem [13]:
$$
p (\mathbf {y} | \mathbf {P}) = \mathbb {E} _ {p (\mathbf {w} | \mathbf {P})} [ \mathbb {1} _ {c (\mathbf {w}) = \mathbf {y}} ] \tag {1}
$$
The WMC counts the possible worlds  $\mathbf{w}^1$  for which  $c$  produces the output  $\mathbf{y}$ , and weights each possible world  $\mathbf{w}$  with  $p(\mathbf{w}|\mathbf{P})$ . In PNL, we want to train a perception model  $f_{\theta}$  to compute a belief  $\mathbf{P} = f_{\theta}(x)$  for an input  $\mathbf{x} \in X$  in which the correct world is likely. Note that possible worlds are not necessarily correct worlds:  $\mathbf{w} = (4,9)$  also sums to 13, but is not a symbolic representation of  $\mathbf{x} = (\mathcal{S},\mathcal{I})$ .
Given this setup, we are interested in efficiently computing the following quantities:
1.  $p(\mathbf{y}|\mathbf{P} = f_{\theta}(\mathbf{x}))$ : We want to find the most likely outputs for the belief  $\mathbf{P}$  that the perception network computes on the input  $\mathbf{x}$ .
2.  $\nabla_{\mathbf{P}}p(\mathbf{y}|\mathbf{P} = f_{\boldsymbol{\theta}}(\mathbf{x}))$ : We want to train our neural network  $f_{\boldsymbol{\theta}}$ , which requires computing the gradient of the WMC problem.
3.  $p(\mathbf{w}|\mathbf{y}, \mathbf{P} = f_{\theta}(\mathbf{x}))$ : We want to find likely worlds given a predicted output and a belief about the perceived digits. The probabilistic logic programming literature calls  $\mathbf{w}^* = \arg \max_{\mathbf{w}} p(\mathbf{w}|\mathbf{y}, \mathbf{P})$  the most probable explanation (MPE) [50].
2.3 The problem with exact inference for WMC
The three quantities introduced in Section 2.2 require calculating or estimating the WMC problem of Equation 1. However, the exact computation of the WMC is #P-hard, which is above NP-hard. Thus, we would need to do a potentially exponential-time computation for each training iteration and test query. Existing PNL methods use probabilistic circuits (PCs) to speed up this computation [60, 28, 35, 57]. PCs compile a logical formula into a circuit for which many inference queries are linear in the size of the circuit. PCs are a good choice when exact inference is required but do not overcome the inherent exponential complexity of the problem: the compilation step is potentially exponential in time and memory, and there are no guarantees the size of the circuit is not exponential.
The Multi-digit MNISTAdd task is excellent for studying the scaling properties of WMC. We can increase the complexity of MNISTAdd exponentially by considering not only the sum of two single digits (called  $N = 1$ ) but the sum of two numbers with multiple digits. An example of  $N = 2$  would be  $\sqrt{2} + \sqrt{3} = 135$ . There are 64 ways to sum to 135 using two numbers with two digits. Contrast this to summing two digits: there are only 6 ways to sum to 13. Each increase of  $N$  leads to 10 times more options to consider for exact inference. Our experiments in Section 4 will show that approximate inference can solve this problem up to  $N = 15$ . Solving this using exact inference would require enumerating around  $10^{15}$  options for each query.
3 A-NESI: Approximate Neurosymbolic Inference
Our goal is to reduce the inference complexity of PNL to allow training neurosymbolic models on much more complex problems. To this end, in the following subsections, we introduce Approximate Neurosymbolic Inference (A-NESI). A-NESI approximates the three quantities of interest from Section 2, namely  $p(\mathbf{y}|\mathbf{P})$ ,  $\nabla_{\mathbf{P}}p(\mathbf{y}|\mathbf{P})$  and  $p(\mathbf{w}|\mathbf{y},\mathbf{P})$ , using neural networks. We give an overview of our method in Figure 1.
3.1 Inference models
A-NESI uses an inference model  $q_{\phi, \psi}$  defined as
$$
q _ {\phi , \psi} (\mathbf {w}, \mathbf {y} | \mathbf {P}) = q _ {\phi} (\mathbf {y} | \mathbf {P}) q _ {\psi} (\mathbf {w} | \mathbf {y}, \mathbf {P}). \tag {2}
$$
We call  $q_{\phi}(\mathbf{y}|\mathbf{P})$  the prediction model and  $q_{\psi}(\mathbf{w}|\mathbf{y},\mathbf{P})$  the explanation model. The prediction model should approximate the WMC problem of Equation 1, while the explanation model should predict likely worlds w given outputs y and beliefs P. One way to model  $q_{\phi,\psi}$  is by considering  $W$  and  $Y$  as two sequences and defining an autoregressive generative model over these sequences:
$$
q _ {\phi} (\mathbf {y} \mid \mathbf {P}) = \prod_ {i = 1} ^ {k _ {Y}} q _ {\phi} \left(y _ {i} \mid \mathbf {y} _ {1: i - 1}, \mathbf {P}\right), \quad q _ {\psi} (\mathbf {w} \mid \mathbf {y}, \mathbf {P}) = \prod_ {i = 1} ^ {k _ {W}} q _ {\psi} \left(w _ {i} \mid \mathbf {y}, \mathbf {w} _ {1: i - 1}, \mathbf {P}\right) \tag {3}
$$
'Possible worlds are also called 'models'. We refrain from using this term to prevent confusion with 'neural network) models'.
Algorithm 1 Compute inference model loss fit prior  $p(\mathbf{P})$  on  $\mathbf{P}_1,\dots,\mathbf{P}_k$ $\mathbf{P}\sim p(\mathbf{P})$ $\mathbf{w}\sim p(\mathbf{w}|\mathbf{P})$ $\mathbf{y}\gets c(\mathbf{w})$  return  $\phi +\alpha \nabla_{\phi}\log q_{\phi}(\mathbf{y}|\mathbf{P})$
Algorithm 2 A-NESI training loop  
Input: dataset  $\mathcal{D}$ , params  $\theta$ , params  $\phi$   
beliefs  $\leftarrow []$   
while not converged do  
 $(\mathbf{x}, \mathbf{y}) \sim \mathcal{D}$ $\mathbf{P} \leftarrow f_{\theta}(\mathbf{x})$   
update beliefs with  $\mathbf{P}$ $\phi \leftarrow$  Algorithm 1(beliefs,  $\phi$ )  
 $\theta \leftarrow \theta + \alpha \nabla_{\theta} \log q_{\phi}(\mathbf{y}|\mathbf{P})$
Figure 2: The training loop of A-NESI.
This factorization makes the inference model highly flexible. We can use simpler models if we know the dependencies between variables in  $W$  and  $Y$ . The factorization is computationally linear in  $k_{W} + k_{Y}$ , instead of exponential in  $k_{W}$  for exact inference. During testing, we use a beam search to find the most likely prediction from  $q_{\phi, \psi}(\mathbf{w}, \mathbf{y} | \mathbf{P})$ . If the method successfully trained the perception model, then its entropy is low and a beam search should easily find the most likely prediction [37].
There are no restrictions on the architecture of the inference model  $q_{\phi}$ . Any neural network with appropriate inductive biases and parameter sharing to speed up training can be chosen. For instance, CNNs over grids of variables, graph neural networks [27, 48] for reasoning problems on graphs, or transformers for sets or sequences [55].
We use the prediction model to train the perception model  $f_{\theta}$  given a dataset  $\mathcal{D}$  of tuples  $(\mathbf{x}, \mathbf{y})$ . Our novel loss function trains the perception model by backpropagating through the prediction model:
$$
\mathcal {L} _ {\text {P e r c}} (\mathcal {D}, \boldsymbol {\theta}) = - \log q _ {\phi} (\mathbf {y} | \mathbf {P} = f _ {\boldsymbol {\theta}} (\mathbf {x})), \quad \mathbf {x}, \mathbf {y} \sim \mathcal {D} \tag {4}
$$
The gradients of this loss are biased due to the error in the approximation  $q_{\phi}$ , but it has no variance outside of sampling from the training dataset.
3.2 Training the inference model
We define two variations of our method. The prediction-only variant (Section 3.2.1) uses only the prediction model  $q_{\phi}(\mathbf{y}|\mathbf{P})$ , while the explainable variant (Section 3.2.4) also uses the explanation model  $q_{\psi}(\mathbf{w}|\mathbf{y},\mathbf{P})$ .
Efficient training of the inference model relies on two design decisions. The first is a descriptive factorization of the output space  $Y$ , which we discuss in Section 3.2.2. The second is using an informative belief prior  $p(\mathbf{P})$ , which we discuss in Section 3.2.3.
We first define the forward process that uses the symbolic function  $c$  to generate training data:
$$
p (\mathbf {w}, \mathbf {y} | \mathbf {P}) = p (\mathbf {w} | \mathbf {P}) p (\mathbf {y} | \mathbf {w}, \mathbf {P}) = p (\mathbf {w} | \mathbf {P}) \mathbb {1} _ {c (\mathbf {w}) = \mathbf {y}} \tag {5}
$$
We take some example world  $\mathbf{w}$  and deterministically compute the output of the symbolic function  $c(\mathbf{w})$ . Then, we compute whether the output  $c(\mathbf{w})$  equals  $\mathbf{y}$ . Therefore,  $p(\mathbf{w}, \mathbf{y} | \mathbf{P})$  is 0 if  $c(\mathbf{w}) \neq \mathbf{y}$  (that is,  $\mathbf{w}$  is not a possible world of  $\mathbf{y}$ ).
The belief prior  $p(\mathbf{P})$  allows us to generate beliefs  $\mathbf{P}$  for the forward process. That is, we generate training data for the inference model using
$$
\begin{array}{l} p (\mathbf {P}, \mathbf {w}) = p (\mathbf {P}) p (\mathbf {w} | \mathbf {P}) \\ \mathbf {P} _ {\text {m a x}} = p (\mathbf {P}, m) = m _ {\text {m a x}} (m) \end{array} \tag {6}
$$
where  $\mathbf{P},\mathbf{w}\sim p(\mathbf{P},\mathbf{w}),\quad \mathbf{y} = c(\mathbf{w})$
The belief prior allows us to train the inference model with synthetic data: The prior and the forward process define everything  $q_{\phi}$  needs to learn. Note that the sampling process  $\mathbf{P}, \mathbf{w} \sim p(\mathbf{P}, \mathbf{w})$  is fast and parallelisable. It involves sampling from a Dirichlet distribution, and then sampling from a categorical distribution for each dimension of  $\mathbf{w}$  based on the sampled parameters  $\mathbf{P}$ .
3.2.1 Training the prediction-only variant
In the prediction-only variant, we only train the prediction model  $q_{\phi}(\mathbf{y}|\mathbf{P})$ . We use the samples generated by the process in Equation 6. We minimize the expected cross entropy between  $p(\mathbf{y}|\mathbf{P})$
and  $q_{\phi}(\mathbf{y}|\mathbf{P})$  over the prior  $p(\mathbf{P})$ :
$$
\mathcal {L} _ {\text {P r e d}} (\phi) = - \log q _ {\phi} (c (\mathbf {w}) | \mathbf {P}), \quad \mathbf {P}, \mathbf {w} \sim p (\mathbf {P}, \mathbf {w}) \tag {7}
$$
See A for a derivation. In the loss function defined in Equation 7, we estimate the expected cross entropy using samples from  $p(\mathbf{P}, \mathbf{w})$ . We use the sampled world  $\mathbf{w}$  to compute the output  $\mathbf{y} = c(\mathbf{w})$  and increase its probability under  $q_{\phi}$ . Importantly, we do not need to use any data to evaluate this loss function. We give pseudocode for the full training loop in Figure 2.
3.2.2 Output space factorization
The factorization of the output space  $Y$  introduced in Section 2 is one of the key ideas that allow efficient learning in A-NESI. We will illustrate this with MNISTAdd. As the number of digits  $N$  increases, the number of possible outputs (i.e., sums) is  $2 \cdot 10^{N} - 1$ . Without factorization, we would need an exponentially large output layer. We solve this by predicting the individual digits of the output so that we need only  $N \cdot 10 + 2$  outputs similar to [3]. Furthermore, recognizing a single digit of the sum is easier than recognizing the entire sum: for its rightmost digit, only the rightmost digits of the input are relevant.
Choosing the right factorization is crucial when applying A-NESI. A general approach is to take the CNF of the symbolic function and predict each clause's truth value. However, this requires grounding the formula, which can be exponential. Another option is to predict for what objects a universally quantified formula holds, which would be linear in the number of objects.
3.2.3 Belief prior design
How should we choose the  $\mathbf{P}$ s for which we train  $q_{\phi, \psi}$ ? A naive method would use the perception model  $f_{\theta}$ , sample some training data  $\mathbf{x}_1, \ldots, \mathbf{x}_k \sim \mathcal{D}$  and train the inference model over  $\mathbf{P}_1 = f_{\theta}(\mathbf{x}_1), \ldots, \mathbf{P}_k = f_{\theta}(\mathbf{x}_k)$ . However, this means the inference model is only trained on those  $\mathbf{P}$  occurring in the training data. Again, consider the Multi-digit MNISTAdd problem. For  $N = 15$ , we have a training set of 2000 sums, while there are  $2 \cdot 10^{15} - 1$  possible sums. By simulating many beliefs, the inference model sees a much richer set of inputs and outputs, allowing it to generalize.
A better approach is to fit a Dirichlet prior  $p(\mathbf{P})$  on  $\mathbf{P}_1, \dots, \mathbf{P}_k$  that covers all possible combinations of numbers. We choose a Dirichlet prior since it is conjugate to the discrete distributions. For details, see Appendix F. During hyperparameter tuning, we found that the prior needs to be high entropy to prevent the inference model from ignoring the inputs  $\mathbf{P}$ . Therefore, we regularize the prior with an additional term encouraging high-entropy Dirichlet distributions.
3.2.4 Training the explainable variant
The explainable variant uses both the prediction model  $q_{\phi}(\mathbf{y}|\mathbf{P})$  and the optional explanation model  $q_{\psi}(\mathbf{w}|\mathbf{y},\mathbf{P})$ . When training the explainable variant, we use the idea that both factorizations of the joint should have the same probability mass, that is,  $p(\mathbf{w},\mathbf{y}|\mathbf{P}) = q_{\phi,\psi}(\mathbf{w},\mathbf{y}|\mathbf{P})$ . To this end, we use a novel joint matching loss inspired by the theory of GFlowNets [9, 10], in particular, the trajectory balance loss introduced by [33] which is related to variational inference [34]. For an in-depth discussion, see Appendix E. The joint matching loss is essentially a regression of  $q_{\phi,\psi}$  onto the true joint  $p$  that we compute in closed form:
$$
\mathcal {L} _ {E x p l} (\boldsymbol {\phi}, \boldsymbol {\psi}) = \left(\log \frac {q _ {\phi , \psi} (\mathbf {w} , c (\mathbf {w}) | \mathbf {P})}{p (\mathbf {w} | \mathbf {P})}\right) ^ {2}, \quad \mathbf {P}, \mathbf {w} \sim p (\mathbf {P}, \mathbf {w}) \tag {8}
$$
Here we use that  $p(\mathbf{w}, c(\mathbf{w})|\mathbf{P}) = p(\mathbf{w}|\mathbf{P})$  since  $c(\mathbf{w})$  is deterministic. Like when training the prediction-only variant, we sample a random belief  $\mathbf{P}$  and world  $\mathbf{w}$  and compute the output  $\mathbf{y}$ . Then we minimize the loss function to match the joints  $p$  and  $q_{\phi,\psi}$ . We further motivate the use of this loss in Appendix D. Instead of a classification loss like cross-entropy, the joint matching loss ensures  $q_{\phi,\psi}$  does not become overly confident in a single prediction and allows spreading probability mass easier.
3.3 Symbolic pruner
An attractive option is to use symbolic knowledge to ensure the inference model only generates valid outputs. We can compute each factor  $q_{\psi}(w_i|\mathbf{y}, \mathbf{w}_{1:i-1}, \mathbf{P})$  (both for world and output variables)
Figure 3: Example rollout sampling an explainable variant on input  $\mathbf{x} = (\mathbf{S},\mathbf{Z})$ . For  $y_{2}$ , we prune option 9, as the highest attainable sum is  $9 + 9 = 18$ . For  $w_{1}$ ,  $\{0,\dots,3\}$  are pruned as there is no second digit to complete the sum.  $w_{2}$  is deterministic given  $w_{1}$ , and prunes all branches but 8.
$$
\mathbf {P} = f _ {\theta} (\widehat {\mathcal {S}}, \widehat {\mathcal {I}}) \longrightarrow q _ {\phi} (y _ {1} | \mathbf {P}) \longrightarrow q _ {\phi} (y _ {2} | y _ {1}, \mathbf {P}) \longrightarrow q _ {\psi} (w _ {1} | \mathbf {y}, \mathbf {P}) \longrightarrow q _ {\psi} (w _ {2} | w _ {1}, \mathbf {y}, \mathbf {P})
$$
using a neural network  $\hat{q}_{\psi ,i}$  and a symbolic pruner  $s_{\mathbf{y},\mathbf{w}1:i - 1}:W_i\to \{0,1\}$ :
$$
q _ {\psi} \left(w _ {i} = j \mid \mathbf {y}, \mathbf {w} _ {1: i - 1}, \mathbf {P}\right) = \frac {\hat {q} _ {\psi} \left(w _ {i} = j \mid \mathbf {y} , \mathbf {w} _ {1 : i - 1} , \mathbf {P}\right) s _ {\mathbf {y} , \mathbf {w} _ {1 : i - 1}} (j)}{\sum_ {j ^ {\prime} \in W _ {i}} \hat {q} _ {\psi} \left(w _ {i} = j ^ {\prime} \mid \mathbf {y} , \mathbf {w} _ {1 : i - 1} , \mathbf {P}\right) s _ {\mathbf {y} , \mathbf {w} _ {1 : i - 1}} \left(j ^ {\prime}\right)} \tag {9}
$$
The symbolic pruner sets the probability mass of certain choices for the variable  $w_{i}$  to zero. Then,  $q_{\psi}$  is computed by renormalizing. If we know that by expanding  $\mathbf{w}_{1:i-1}$  it will be impossible to produce a possible world for  $\mathbf{y}$ , we can set the probability mass under that branch to 0: we will know that  $p(\mathbf{w}, \mathbf{y}) = 0$  for all such branches. In Figure 3 we give an example for single-digit MNISTAdd. Symbolic pruning significantly reduces the number of branches our algorithm needs to explore during training. Moreover, symbolic pruning is critical in settings where verifiability and safety play crucial roles, such as medicine. We discuss the design of symbolic pruners  $s$  in Appendix G.
We study three Neurosymbolic reasoning tasks to evaluate the performance and scalability of A-NeSI: Multi-digit MNISTAdd [37], Visual Sudooku Puzzle Classification [4] and Wcrafth path planning. Code is available at https://github.com/HEmile/a-nesi. We used the ADAM optimizer throughout.
A-NESI has two prediction methods. 1) Symbolic prediction uses the symbolic reasoning function  $c$  to compute the output:  $\hat{\mathbf{y}} = c(\arg \max_{\mathbf{w}} p(\mathbf{w}|\mathbf{P} = f_{\theta}(\mathbf{x})))$ . 2) Neural prediction predicts with the prediction network  $q_{\phi}$  using a beam search:  $\hat{\mathbf{y}} = \arg \max_{\mathbf{y}} q_{\phi}(\mathbf{y}|\mathbf{P} = f_{\theta}(\mathbf{x}))$ . In our studied tasks, neural prediction cannot perform better than symbolic prediction. However, we still use the prediction model to efficiently train the perception model in the symbolic prediction setting. We consider the prediction network adequately trained if it matches the accuracy of symbolic prediction.
4.1 Multi-digit MNISTAdd