NeSyA: Neurosymbolic Automata Nikolaos Manginas, Georgios Paliouras, Luc De Raedt Abstract Neurosymbolic (NeSy) AI has emerged as a promising direction to integrate neural and symbolic reasoning. Unfortunately, little effort has been given to developing NeSy systems tailored to sequential/temporal problems. We identify symbolic automata (which combine the power of automata for temporal reasoning with that of propositional logic for static reasoning) as a suitable formalism for expressing knowledge in temporal domains. Focusing on the task of sequence classification and tagging we show that symbolic automata can be integrated with neural-based perception, under probabilistic semantics towards an end-to-end differentiable model. Our proposed hybrid model, termed NeSyA ( Ne uro Sy mbolic A utomata) is shown to either scale or perform more accurately than previous NeSy systems in a synthetic benchmark and to provide benefits in terms of generalization compared to purely neural systems in a real-world event recognition task. Code is available at: https://github.com/nmanginas/nesya . † † footnotetext: Equal supervision 1 Introduction Sequence classification/tagging is a ubiquitous task in AI. Purely neural models, including LSTMs ( Hochreiter, 1997 ) and Transformers ( Vaswani, 2017 ) , have shown exemplary performance in processing sequences with complex high-dimensional inputs. Nonetheless, various shortcomings still exist in terms of generalization, data-efficiency, explainability and compliance to domain or commonsense knowledge. NeSy AI ( Garcez and Lamb, 2023 ) aims to integrate neural learning and symbolic reasoning, possibly aiding in the afformentioned limitations of purely neural systems. Recently, various NeSy systems have been developed for sequential/temporal problems ( Winters et al., 2022 ; De Smet et al., 2024 ; Umili et al., 2023b ) , with large differences among them, in terms of semantics, inference procedures, and scalability of the proposed hybrid models. In this work, we identify symbolic automata as an attractive low-level representation of complex temporal properties. These differ from classical automata as they support symbolic transitions between states (defined in propositional logic), thus combining temporal reasoning (through the automaton) and atemporal reasoning (through the logical transitions). We show that symbolic automata can be efficiently integrated with neural-based perception and thereby extended to subsymbolic domains. Figure 1 illustrates the core NeSyA architecture in a running example, which is used throughout the paper. The key characteristics of NeSyA that can be used for comparison to existing NeSy systems, are: [C1] its focus on temporal domains, [C2] its probabilistic semantics, [C3] its capacity to integrate static logical reasoning into temporal patterns, [C4] its efficient and exact inference scheme based on matrices and knowledge compilation ( Darwiche and Marquis, 2002 ) . q_{0} start q_{1} q_{2} \neg\mathrm{tired}\wedge\neg\mathrm{blocked} \mathrm{tired}\vee\mathrm{blocked} \neg\mathrm{fast}\wedge(\mathrm{tired}\vee\mathrm{blocked}) \neg\mathrm{tired}\wedge\neg\mathrm{blocked}\wedge\neg\mathrm{fast} \mathrm{fast} \mathrm{true} \mathrm{P}(\mathrm{accept}\ |\ \raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/1.png}},\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/0.png}},\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{ images/2.png}})=0.78 neural extraction differentiable inference Figure 1: Symbolic automata (middle) are used to reason over sequences of subsymbolic inputs (top) from which information is extracted with the aid of a neural network, performing multilabel classification. For instance, for the image , the correct symbol grounding is \{\mathrm{tired},\neg\mathrm{blocked},\neg\mathrm{fast}\} . The symbolic automaton shown captures the following logic: If the driver is tired or the road is blocked, then in the next timestep they should not be going fast. NeSyA computes the probability of the SFA accepting the input sequence (bottom), which is then used for learning. The closest system to our work is FuzzyA ( Umili et al., 2023b ) , which attempts to address the NeSy integration of LTL f with neural networks. That system differs from NeSyA primarily in terms of [C2] , as it is based on fuzzy logic and specifically on Logic Tensor Networks ( Badreddine et al., 2022 ) . As we shall show in this paper, probabilistic semantics can provide significant benefits, in terms of predictive accuracy, over fuzzy logic, as used in FuzzyA . On the other hand, NeSyA differs from approaches like the Semantics Loss ( SL ) ( Xu et al., 2018 ) and DeepProbLog ( Manhaeve et al., 2018 ) , in terms of [C1] , as they are not tailored to temporal reasoning. In this paper, we shall show that this makes them scale considerably worse than NeSyA when faced with problems with a temporal component. The more recent DeepStochLog system ( Winters et al., 2022 ) is based on unification grammars and therefore differs from NeSyA in terms of both [C1] but mostly [C4] . Our experiments show that this difference makes DeepStochLog orders of magnitude slower than NeSyA . Further, systems based on neural networks and classical automata, such as ( Umili et al., 2023a ; Umili and Capobianco, 2024 ) differ from NeSyA in terms of [C3] , since classical automata lack symbolic transitions and support for atemporal reasoning. Lastly, ( De Smet et al., 2024 ) is based on very expressive models in mixed discrete and continuous domains. It is based on approximate inference, thus differing from NeSyA in terms of [C4] . Our contributions are as follows: • We introduce NeSyA a probabilistic NeSy system for sequence classification and tagging, which combines automata, logic and neural networks. • We introduce an efficient algorithm for inference in NeSyA , utilizing matrix-based automata inference and knowledge compilation based approaches for logical inference ( Darwiche and Marquis, 2002 ) . • On a synthetic sequence classification domain, we show that NeSyA leads to large performance benefits over FuzzyA ( Umili et al., 2023b ) and scales orders of magnitude better than DeepStochLog ( Winters et al., 2022 ) , which is also based on a probabilistic semantics. • On a real-world event recognition domain we show that NeSyA can lead to a more accurate event recognition system, compared to purely neural approaches. 2 Background 2.1 Propositional Logic and Traces We shall use lowercase to denote propositional variables, e.g. \mathrm{blocked} . A propositional formula \phi over a set of variables V is defined as: \phi::=V\ |\ \neg\phi_{1}\ |\ \phi_{1}\land\phi_{2}\ |\ \phi_{1}\lor\phi_{2}. These connectives are sufficient to then define \rightarrow , etc. An interpretation \omega\subseteq V assigns a truth value to each variable. We use subsets to denote interpretations. For instance for V=\{\mathrm{tired},\mathrm{blocked},\mathrm{fast}\} the interpretation \omega=\{\mathrm{tired},\mathrm{blocked}\} is shorthand for \{\mathrm{tired},\mathrm{blocked},\neg\mathrm{fast}\} . If an interpretation \omega satisfies a formula \phi we write \omega\models\phi and \omega is called a model of \phi . The semantics of propositional logic are given in terms of interpretations. Traces generalize interpretations for temporal domains. A trace over variables V , \pi=(\omega_{1},\omega_{2},\dots,\omega_{n}) is a sequence of interpretations, with \omega_{i}\subseteq V . We use \pi_{t} to denote the interpretation \omega_{t} at timestep t . 2.2 SFA : Symbolic Automata A symbolic automaton ( SFA ) is defined as: \mathcal{A}=(V,Q,q_{0},\delta,F), where V is a set of variables, Q a set of states, q_{0}\in Q the initial state, \delta:Q\times Q\rightarrow B(V) is the transition function and F\subset Q is the set of accepting states. B(V) is used to denote the set of all valid formulae in propositional logic over variables V . The difference between an SFA and a classical automaton is that \delta is given in a factored form, e.g. \delta(q_{0},q_{1})=\mathrm{tired}\lor\mathrm{blocked} in Figure 1 . One can always convert the SFA to a classical automaton by replacing each transition \delta(q,q^{\prime}) with multiple ones representing all models \omega\models\delta(q,q^{\prime}) . This approach does not scale to complex formulae and large sets of variables, as the number of resulting transitions can be exponential in V . This factored transition function is also common in the Markov Decision Process literature ( Guestrin et al., 2003 ) with the goal being to exploit the symbolic nature of the transitions without “propositionalizing”. A symbolic automaton reads traces, i.e. sequences of interpretations (\omega_{1},\dots,\omega_{n}) ( \omega_{i}\subseteq V ) over the variables V . We shall consider deterministic SFA s, in which: \forall q\in Q,\omega\in 2^{V}:\exists!~q^{\prime}:\omega\models\delta(q,q^{\prime}). That is, for any state q\in Q and any interpretation \omega\in 2^{V} exactly one transition outgoing from state q will be satisfied by \omega . For the SFA in Figure 1 consider the transitions outgoing from state q_{0} . For any intepretation, either (\neg\mathrm{tired}\wedge\neg\mathrm{blocked}) or (\mathrm{tired}\lor\mathrm{blocked}) will be true. If the SFA ends up in an accepting state after reading the trace \pi we write \pi\models\mathcal{A} . 2.3 Probabilistic Logical Inference Probabilistic logical inference is the task of computing the probability of a logical formula under uncertain input. For a propositional formula \phi over variables V , let \mathrm{p} denote a probability vector over the same variables. Each element \mathrm{p}[i] therefore denotes the probability of the i th symbol in V being true. The probability of the formula given \mathrm{p} is then defined as: \displaystyle\mathrm{P}(\phi\ |\ \mathrm{p}) \displaystyle=\sum_{\omega\models\phi}\mathrm{P}(\omega\ |\ \mathrm{p}), (1) \displaystyle\text{with}\ \mathrm{P}(\omega\ |\ \mathrm{p}) \displaystyle=\prod_{i\in\omega}\mathrm{p}[i]\prod_{i\notin\omega}1-\mathrm{p}[i]. This task is reducible to weighted model counting ( \mathrm{WMC} ), one of the most widely-used approaches to probabilistic logical inference ( Chavira and Darwiche, 2008 ) . As computing \mathrm{WMC} involves summing over all models of a propositional formula, it lies in the \mathrm{\#P} complexity class of counting problems ( Valiant, 1979 ) . Knowledge Compilation ( KC ) ( Darwiche and Marquis, 2002 ) is a common approach to solve \mathrm{WMC} problems. It involves transforming a logical formula to a tractable representation, on which \mathrm{WMC} queries can be cast in linear time. Importantly, once a formula has been compiled to a tractable representation, \mathrm{WMC} cannot only be computed in linear time but also differentiably. The computational complexity of the problem is effectively shifted to an initial compilation phase but can be amortized, since multiple queries can be cast on the compiled representation. Consider for example the formula \phi=\neg\mathrm{fast}\land(\mathrm{tired}\lor\mathrm{blocked}) , i.e. the transition q_{1}\rightarrow q_{1} in Figure 1 . Its compiled form as a d-DNNF circuit ( Darwiche, 2001 ) , one of the tractable KC representations, and the computation of \mathrm{WMC} can be seen in Figure 2 . The logical circuit in Figure 2 (left) is converted to an arithmetic circuit Figure 2 (right) by replacing AND gates with multiplication and OR gates with addition. The weighted model count for the probability vector in Figure 2 can be verified to be correct by: \displaystyle\mathrm{P}(\neg\mathrm{fast}\land(\mathrm{tired}\lor\mathrm{blocked})\ |\ \mathrm{p}=[0.8,0.3,0.6]) \displaystyle=\mathrm{P}(\{\mathrm{tired}\}|\mathrm{p})+\mathrm{P}(\{\mathrm{blocked}\}|\mathrm{p}) \displaystyle+\mathrm{P}(\{\mathrm{tired},\mathrm{blocked}\}|\mathrm{p}) \displaystyle=0.8\times 0.7\times 0.4+0.2\times 0.3\times 0.4+0.8\times 0.3\times 0.4 \displaystyle=0.344. Recall that interpretations are given in shorthand, e.g. \{\mathrm{tired}\} is shorthand for \{\mathrm{tired},\neg\mathrm{blocked},\neg\mathrm{fast}\} . \neg\mathrm{fast}\land(\mathrm{blocked}\lor\mathrm{tired}) \neg\mathrm{fast} \mathrm{tired} \mathrm{blocked} \neg\mathrm{tired} 0.344 * + * 0.4 0.8 0.2 0.3 Figure 2: A d-DNNF circuit for the formula \phi=\neg\mathrm{fast}\land(\mathrm{blocked}\lor\mathrm{tired}) (left) and an arithmetic circuit produced from the d-DNNF circuit (right). The computation of \mathrm{WMC} is shown for the vector \mathrm{p}=[0.8,0.3,0.6] for the symbols \{\mathrm{tired},\mathrm{blocked},\mathrm{fast}\} respectively. 3 Method 3.1 Formulation and Inference We introduce NeSyA as a NeSy extension of the SFA s introduced earlier. Rather than assuming a trace of propositional interpretations \pi=(\omega_{1},\omega_{2},\dots,\omega_{n}) we assume a sequence of subsymbolic observations o=(o_{1},o_{2},\dots,o_{n}) with o_{i}\in\mathbb{R}^{m} . NeSyA is defined as a tuple (\mathcal{A},f_{\theta}) , with \mathcal{A} an SFA over variables V and f_{\theta}:\mathbb{R}^{m}\rightarrow[0,1]^{|V|} a neural network, which computes a probability vector f_{\theta}(o_{t}) over the variables V from the observation o_{t} . Therefore f_{\theta}(o_{t})[i] denotes the probability of the i th variable in V being true given the observation o_{t} . The neural network is used to bridge between the discrete representation of the SFA and the continuous representation of the observations. The resulting model is depicted in graphical model notation in Figure 3 , where q_{t} denotes a discrete random variable over the states of the SFA and o_{t} the input observation at time t . Following ( McCallum et al., 2000 ) , we define \alpha_{t}(q)=P(q\ |\ o_{1},...,o_{t}) as the probability of being in state q at timestep t after seeing the observations (o_{1},...,o_{t}) . \alpha_{t} can be computed recursively (using dynamic programming) as follows: \displaystyle\alpha_{0}(q_{0})=1;~~\alpha_{0}(q)=0~~\forall q\not=q_{0} (2) \displaystyle\alpha_{t+1}(q)=\sum_{q^{\prime}\in Q}\mathrm{P}(q\ |\ q^{\prime},o_{t+1})\ \alpha_{t}(q^{\prime}), \displaystyle\begin{aligned} \text{where}\ \mathrm{P}(q\ |\ q^{\prime},o_{t+1})&=\mathrm{P}(\delta(q^{\prime},q)\ |\ f_{\theta}(o_{t+1}))\\ &=\sum_{\omega\models\delta(q^{\prime},q)}\mathrm{P}(\omega\ |\ f_{\theta}(o_{t+1})).\end{aligned} Thus, to update the probability of being in each state, one must first compute the probabilities of the logical formulae in the SFA ’s transitions given the outputs of the neural network for the current observation. Instead of naively summing over all models of each formula, we use KC to make the computation efficient. The state update, which is similar to the one in Hidden Markov Models, can be captured via matrix operations and is therefore amenable to parallelization and execution on GPUs. It is well-known that \alpha_{t} can be represented with a vector of size |Q| , whose elements are the probabilities of being in each state at timestep t . In what follows we adopt this notation. q_{0} q_{1} q_{2} o_{1} o_{2} Figure 3: Graphical model for NeSyA . Following the approach used in ( McCallum et al., 2000 ) , it resembles a Hidden Markov Model with the arrows between states and observations reversed. The random variables q_{t} take values from Q , the state space of the SFA , and the random variables o_{t} take values from high-dimensional continuous spaces. Running example computation: Consider the SFA in Figure 1 . Let the first observation be o_{1}=\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/1.png}} and let f_{\theta}(o_{1})=[0.8,0.3,0.6] the output of the neural network. We define the transition matrix T(o_{i}) where T(o_{i})[q^{\prime},q]=\mathrm{P}(\delta(q^{\prime},q)\ |\ f_{\theta}(o_{i})) . We thus have: T(\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/1.png}})=\begin{bmatrix}0.14&0.86&0\\ 0.056&0.344&0.6\\ 0&0&1\\ \end{bmatrix}. The calculation of the entry T(\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/1.png}})[q_{1},q_{1}] was shown in Section 2.3 . Similarly, the computation of other entries is performed by propagating an arithmetic circuit for each transition, given the neural network predictions for the current observation. Observe that the sum of each row in the transition matrix, i.e. the total mass out of each state is 1 . This is a direct consequence of the deterministic propertry of the SFA , where exactly one outgoing transition from each state will be true for any possible intepretation. It also ensures that \sum_{q\in Q}\alpha_{t}[q]=1 for all t . We start with \alpha_{0} , where \alpha_{0}[q_{0}]=1 and \alpha_{0}[q]=0 for all q\in Q,\ q\neq q_{0} , We then recursively compute \alpha_{t} for each subsequent timestep. Let o=(o_{1}=\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/1.png}},o_{2}=\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/0.png}}) . Consider the neural network predictions for o_{1} as above and let f_{\theta}(o_{2})=[0.7,0.9,0.3] . We is is \displaystyle\mathrm{\alpha_{2}} \displaystyle=\mathrm{\alpha_{1}}\times T(o_{2}) \displaystyle=\mathrm{\alpha_{0}}\times T(o_{1})\times T(o_{2}) \displaystyle=\begin{bmatrix}1&0&0\end{bmatrix}\times\begin{bmatrix}0.14&0.86&0\\ 0.056&0.344&0.6\\ 0&0&1\\ \end{bmatrix}\times T(o_{2}) \displaystyle=\begin{bmatrix}0.14&0.86&0\end{bmatrix}\times\begin{bmatrix}0.03&0.97&0\\ 0.021&0.679&0.3\\ 0&0&1\end{bmatrix} \displaystyle=\begin{bmatrix}0.023&0.7197&0.258\end{bmatrix}. Depending on the task, the \alpha -recursion can be used in various ways. For sequence classification, one only cares about the state probabilities in the final timestep and would aggregate over accepting states to get the probability of accepting the sequence. Concretely: \mathrm{P}_{\mathrm{accept}}(o)=\sum_{f\in F}\alpha_{n}(f). where n is the length of the sequence. In this case \mathrm{P}_{\mathrm{accept}}(o)=0.023+0.7179=0.742 . In other applications, such as sequence tagging, one is interested about the \alpha values in every timestep. 3.2 Learning For ease of exposition we shall consider the sequence classification task, in which NeSyA is given a subsymbolic sequence o and computes \mathrm{P}_{\mathrm{accept}}(o) . The computation of \mathrm{P}_{\mathrm{accept}}(o) is differentiable with respect to the neural network outputs as the only operations necessary to compute the acceptance probability are: (a) the computation of \mathrm{WMC} which, as shown in Section 2.3 , reduces to propagating an arithmetic circuit comprised of addition, multiplication and subtraction, (b) the \alpha -recursion which is implemented via standard matrix operations, and (c) a summation over the final \alpha values. Therefore, given a dataset of pairs (o,L) , where L\in\{0,1\} is a binary label for the sequence o , one can train the neural component of NeSyA by minimizing a standard supervised learning loss, e.g. \mathcal{L}(o,L)=\mathrm{BCE}(\mathrm{P}_{\mathrm{accept}}(o),L), where \mathrm{BCE} stands for the standard binary cross entropy. This amounts to training the neural network via weak supervision, where no direct labels are given for the symbol grounding of each observation, but rather for the sequence as a whole. This weak-supervision learning setup is common and can be found in ( Manhaeve et al., 2018 ; Yang et al., 2020 ; Winters et al., 2022 ; Umili et al., 2023b ) . More concretely, observe that we don’t require examples of the form (\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/1.png}},\{\mathrm{tired},\neg\mathrm{blocked},\neg\mathrm{fast}\}) , as we would in a fully supervised multilabel problem, but rather of the form ((\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/1.png}},\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/0.png}},\raisebox{-2.84544pt}{\includegraphics[height=11.38092pt]{images/2.png}}),0) . Such high-level labels are in general much fewer in number and more easily attained. Given the differentiability of the model, explained at the start of this subsection, the neural component f_{\theta} is trained via standard gradient descent on the distant labels. 3.3 Semantics and Discussion Consider a sequence of probability vectors (\mathrm{p_{1}},\mathrm{p_{2}},\dots,\mathrm{p_{n}}) with each vector \mathrm{p_{t}} assigning a probability to each proposition v\in V at timestep t . In NeSyA \mathrm{p_{t}}=f_{\theta}(o_{t}) , i.e. these probability vectors are computed via a neural network conditioned on the observation at each timestep, but we ignore the neural component at this stage of the analysis. Given (\mathrm{p_{1}},\dots,\mathrm{p_{n}}) , the probability of trace \pi , a sequence of interpretations, is then: \mathrm{P}(\pi\ |\ (\mathrm{p_{1}},\mathrm{p_{2}},\dots,\mathrm{p_{n}}))=\prod_{t=1}^{n}\mathrm{P}(\pi_{t}\ |\ \mathrm{p}_{t}) To elaborate, the probability of a sequence of interpretations is the product of the probability of each interpretation \pi_{t} given \mathrm{p_{t}} . Theorem 1 ( \alpha -semantics) . It holds that: \alpha_{t}[q]=\sum_{\pi\in\mathrm{traces}(q,t)}\mathrm{P}(\pi\ |\ (\mathrm{p_{1}},\mathrm{p_{2}},\dots,\mathrm{p_{t}})). where \mathrm{traces}(q,t) is the set of all traces which cause the SFA to end up in state q starting from q_{0} in t timesteps. The probability of being in state q at timestep t is then the sum of all such traces (sequences of interpretations) weighted by the probability of each trace given (\mathrm{p_{1}},\dots,\mathrm{p_{t}}) . This directly follows from the graphical model but refer to Appendix A for a proof from first principles. A direct consequence is that for an SFA \mathcal{A} and the sequence (\mathrm{p_{1}},\dots,\mathrm{p_{n}}) of symbol probabilities: \sum_{f\in F}\alpha_{n}[f]=\sum_{\pi\models\mathcal{A}}\mathrm{P}(\pi\ |\ (\mathrm{p_{1}},\mathrm{p_{2}},\dots,\mathrm{p_{n}})). (3) Once the logical transitions of the SFA have been compiled to a tractable form, see Section 2.3 , this computation is polynomial in the number of nodes of the compiled circuits and the number of states of the SFA . This makes the compiled SFA , a tractable device for performing computations over uncertain symbolic sequences. Pattern Sequence Length Method 1 2 3 Accuracy Time Accuracy Time Accuracy Time 10 NeSyA \mathbf{1.0} \mathbf{0.8} \mathbf{0.98}\pm 0.03 \mathbf{1.1} \mathbf{1.0} \mathbf{2.3} FuzzyA 0.91\pm 0.06 10.8 0.70\pm 0.13 22.5 0.78\pm 0.04 29.9 20 NeSyA \mathbf{1.0} \mathbf{1.2} \mathbf{0.99}\pm 0.01 \mathbf{1.7} \mathbf{0.99}\pm 0.01 \mathbf{3} FuzzyA 0.77\pm 0.22 21.4 0.69\pm 0.14 43.7 0.7\pm 0.1 57.7 30 NeSyA \mathbf{1.0} \mathbf{1.7} \mathbf{0.94}\pm 0.11 \mathbf{2.3} \mathbf{0.97}\pm 0.03 \mathbf{3.8} FuzzyA 0.98\pm 0.01 31.7 0.55\pm 0.1 55.9 0.5 86.6 Table 1: Accuracy results on a test set, and timings (in minutes) for NeSyA against FuzzyA averaged across 5 runs, as well as standard deviation (when over 0.01). Both systems are trained with a learning rate of 0.001 following ( Umili et al., 2023b ) . This result is important for extending NeSy systems to the temporal domain. Consider the symbolic component of a NeSy system, e.g. DeepProbLog . It eventually reduces to a propositional formula \phi and relies on the computation of \sum_{\omega\models\phi}\mathrm{P}(\omega\ |\ \mathrm{p}) , where \mathrm{p} is usually the output of a neural network conditioned on an observation. For temporal NeSy systems if the symbolic component can be captured by an SFA \mathcal{A} , then \sum_{\pi\models\mathcal{A}}\mathrm{P}(\pi|\mathrm{p_{1}},\mathrm{p_{2}},\dots,\mathrm{p_{t}}) is computable as shown in Equation 3 . To further motivate the potential efficacy of SFA s as promising low-level representations in the context of NeSy, we note that they are known to capture STRIPS domains as well as temporal logics ( De Giacomo et al., 2013 ) and are thus quite expressive. Hence, it is possible, that SFA s can serve as an efficient compilation target for temporal NeSy systems, much like d-DNNF and similar representations have done for atemporal NeSy systems. Figure 4: Scalability results for NeSyA (solid) and DeepStochLog (dashed) for each of the three patterns tested.The y-axis represents the update time for a single batch of 16 sequences in logarithmic scale and the x-axis the sequence length. The systems were benchmarked for three different patterns of varying complexity both in terms of symbols, as well as states of the automaton. 4 Results In this section we provide empirical results for the performance of NeSyA and its comparison to other NeSy systems, as well as to purely neural ones. We aim to answer the following questions: [Q1] Scalability: How does NeSyA compare to DeepStochLog and FuzzyA in terms of runtime on the same NeSy learning task? [Q2] Accuracy: How does NeSyA compare to FuzzyA in terms of accuracy on the same NeSy learning task? 1 1 1 The accuracy of DeepStochLog is not compared against that of NeSyA , as they generate the same results on the same input. [Q3] Generalization: How does NeSyA compare to purely neural solutions in terms of generalization? All experiments were run on a machine with an AMD Ryzen Threadripper PRO 3955WX 16-Core processor, 128GB of RAM, and 2 NVIDIA RTX A6000 with 50GB of VRAM of which only one was utilized. 4.1 Synthetic Driving We first benchmarked NeSy systems on a synthetic task, which allowed us to control the complexity. In particular, we used the domain introduced as a running example, in which a sequence of images must be classified according to a temporal pattern. Each image represents a set of binary symbols. In the example from Figure 1 the symbols were \{\mathrm{tired},\mathrm{blocked},\mathrm{fast}\} , however we test for sets of up to five symbols. Their truth value is represented via two emojis, one corresponding to the value true and one false. Random Gaussian noise is added to each image to make the mapping between an image and its symbolic interpretation less trivial. We generate three patterns (different SFAs) with 3 , 4 and 6 SFA states and 3 , 4 and 5 symbols respectively. For each pattern, we generated 100 random trajectories which satisfy the pattern (positive) and 100 negative ones. We use the same setup for generating a training and a testing set. The neural component of all systems is a CNN. The learning task is as described in Section 3.2 , where the neural component must perform symbol grounding without direct supervision. Instead supervision is provided at the sequence level and the neural component is trained weakly. We benchmarked against DeepStochLog ( Winters et al., 2022 ) and DeepProblog ( Manhaeve et al., 2018 ) in terms of scalability and with FuzzyA ( Umili et al., 2023b ) both in terms of scalability and accuracy. Figure 4 shows the comparison of NeSyA against the DeepStochLog system on temporal patterns of ranging complexity in the synthetic driving benchmark. The DeepProblog system lagged behind the other two considerably and therefore is omitted from the results for brevity. Accuracy results are also omitted here, since all three systems are equivalent in their computation and learning setup and therefore perform identically in terms of accuracy. In terms of computational performance, NeSyA does significantly better than DeepStochLog , being on average two orders of magnitude faster. As an indication, for the most complex task and a sequence length of 30 , NeSyA takes 0.08 seconds for a single batch update and DeepStochLog takes about 30 seconds, rendering the latter system of limited practical use. As an indication of the difference against DeepProbLog , for the simplest pattern and a single sequence of length 15 , the update time for DeepProbLog is 140 seconds compared to 0.02 seconds for NeSyA . Next, in Table 1 we show accuracy and scalability results of NeSyA against the FuzzyA system. NeSyA , which interfaces between the SFA and the neural representations using probability, seems to offer a much more robust NeSy solution. FuzzyA delivers significantly lower accuracy compared to NeSyA , especially as sequence length grows. Further FuzzyA lags significantly in terms of scalability. Figure 5: Sample of the CAVIAR data. Models are given the two bounding boxes per timestep instead of the complete image, in order to make the task simpler for the neural component. Along with the pair of bounding boxes, a \mathrm{close(p1,p2)} feature is provided, which captures whether the two people are close to each other.The CNN for NeSyA must ground one bounding box to the symbols \mathrm{walking(p1)} , \mathrm{running(p1)} , \mathrm{active(p1)} , \mathrm{inactive(p1)} and correspondingly to \mathrm{p2} for the second bounding box. The correct grounding for this image is \mathrm{active(p1)} and \mathrm{walking(p2)} . These are the low-level activities performed by each person. The high-level activities performed by the pair are annotated for each image in one of the three classes \mathrm{no\_event} , \mathrm{meeting} , \mathrm{moving} . For the image shown here the annotation is \mathrm{moving} . The results on our synthetic benchmark allow us to affirmatively answer [Q1] and [Q2] . NeSyA seems to scale better than both DeepStochLog and FuzzyA for even the simplest patterns considered here, often by very large margins. Further, our system is more accurate than FuzzyA , with the difference in performance becoming very large for large sequence lengths and complex patterns. 4.2 Event Recognition In our second experiment we compared NeSyA against pure neural solutions on an event recognition task from the CAVIAR benchmark dataset 2 2 2 https://homepages.inf.ed.ac.uk/rbf/CAVIARDATA1/ . The task was to recognize events performed by pairs of people in raw video data. We focused on two of the events present in CAVIAR , namely \mathrm{moving} and \mathrm{meeting} , which appear more frequently in the data, and a third \mathrm{no\_event} class. We present three methods; NeSyA a CNN-LSTM and a CNN-Transformer. The data consists of 8 training and 3 testing sequences. The label distribution for the training data is 1183 frames of \mathrm{no\_event} , 851 frames of \mathrm{moving} and 641 frames of \mathrm{meeting} . For the test set, these are 692 , 256 and 894 respectively. The mean sequence length is 411 with a minimum length of 82 and a maximum length of 1054 . We use the macro \mathrm{F1} score for evaluation of all models. \mathrm{no\_event} \mathrm{moving} \mathrm{meeting} \begin{aligned} &\mathrm{initiated}\mathrm{(moving)}\leftarrow\\ &\hskip 8.50012pt\mathrm{walking(p1)}\land\mathrm{walking(p2)}\land\mathrm{close(p1,p2)}\\ &\dots\\ &\mathrm{terminated}\mathrm{(meeting)}\leftarrow\\ &\hskip 8.50012pt\neg\mathrm{close(p1,p2)}\land(\mathrm{walking(p1)}\lor\mathrm{walking(p2)})\\ &\hskip 8.50012pt\lor\mathrm{running(p1)}\lor\mathrm{running(p2)}\end{aligned} initiated(moving) terminated(moving) initiated(meeting) terminated(meeting) Figure 6: The SFA used for the CAVIAR experiments. It defines transitions between two classes meeting and moving and a third no-event class. Only a subset of the transition logic is shown for brevity. In the case that no outgoing transition from a state is satisfied the SFA loops in its current state. Learning rate 0.001 0.0001 0.00001 #Parameters Train Test Train Test Train Test NeSyA 258884 \mathbf{0.81}\pm 0.13 \mathbf{0.60}\pm 0.18 0.87\pm 0.03 \underline{\mathbf{0.85}\pm 0.20} 0.86\pm 0.10 \mathbf{0.81}\pm 0.18 CNN-LSTM 399683 0.70\pm 0.23 \underline{0.56\pm 0.21} 0.84\pm 0.08 0.35\pm 0.19 0.17\pm 0.05 0.15\pm 0.06 CNN-Transformer 2659767 0.72\pm 0.26 0.40\pm 0.10 \mathbf{1.00}\pm 0.00 0.68\pm 0.16 \mathbf{0.97}\pm 0.02 \underline{0.78\pm 0.14} Table 2: Results for the CAVIAR dataset. Performance is averaged over 10 random seeds. The metric reported is macro \mathrm{F1} score. We present results for 3 different learning rates as the dataset is small and constructing a validation split to tune for the learning rate would further reduce the size of the training data. For all systems training is stopped by monitoring the training loss with a patience of 10 epochs. Best test results for each method are underlined. The CAVIAR data is annotated at a frame level with bounding boxes of the people in the scene, as well as with low-level activities they perform, such as walking and running. From the raw data, we extract sequences of two bounding boxes per timestep, as well as a boolean feature of whether the distance between the bounding boxes is smaller than some threshold. Refer to Figure 5 for an overview. The symbolic component of NeSyA in this case is a three-state automaton, capturing a variant of the Event Calculus ( Kowalski and Sergot, 1986 ) programs for CAVIAR found in ( Artikis et al., 2014 ) and can be seen in Figure 6 . We use the SFA to label the sequence with the current high-level event in each frame given the ground truth labels for the low level activities. The true high-level events are also given in the CAVIAR data, but the labels are noisy, i.e. there is some disagreement between the start and end points of the high-level events generated by the logic and those provided by human annotators. Using the labels generated by the SFA , we assume perfect knowledge, i.e. that the symbolic component of NeSyA can perfectly retrieve the high-level events, given the low-level activities. Learning with a label noise is beyond the scope of this work. The task in CAVIAR is therefore to tag a sequence of pairs of bounding boxes, along with a boolean distance feature, with the high-level event being performed in each timestep. For NeSyA each bounding box is processed by a CNN which gives a probability for each of the low-level activities (walking, running, active and inactive). Combining this with the feature \mathrm{close(p1,p2)} , these are then passed through the SFA which outputs the probability of each high-level event per timestep. As a baseline, we drop the final linear projection of the CNN used for NeSyA . The resulting CNN computes a 64 -dimensional embedding for each bounding box. We concatenate the embeddings of the bounding boxes along with the distance feature finally producing a 129 -dimensional embedding per frame. This embedding is then given to either an LSTM or a Transformer, whose hidden state is projected to the three high-level event classes. All systems are trained by computing a cross entropy loss on the high-level event predictions in every timestep of each sequence. The supervision is therefore in the frame level contrary to the experiment in Section 4.1 where supervision was on the sequence level. For NeSyA the loss in the CAVIAR dataset is: \mathcal{L}(o,L)=\sum_{t\in\{1,\dots,n\}}\mathrm{CE}(\alpha_{t},L_{t}), where n denotes the sequence length, \alpha_{t} the probabilities of being in each state of SFA at timestep t (and therefore of emitting each label) and L_{t} denotes the true high-level event label for that timestep, e.g. \mathrm{meeting} . For the pure neural solutions \alpha_{t} is replaced with the output of a linear projection on the LSTM/Transformer hidden state at timestep t . The performance of the three systems can be seen in Table 2 . The results in Table 2 allow us to also answer [Q3] affirmatively. The inclusion of knowledge about the structure of the high-level events based on the low-level activities aids in generalization and the discrepancy between train and test performance is generally small for NeSyA and larger for purely neural solutions in this low data regime. The Transformer baseline is able to compete with NeSyA , albeit with an order of magnitude more parameters. It is interesting that 2.5 million parameters (the difference between NeSyA and the CNN-Transformer) are necessary to find a solution that delivers comparable performance with the three state SFA and simple transition logic used by NeSyA as background knowledge. The results in CAVIAR are to be taken with a grain of salt as standard deviations are high due to the small size of the data which causes outlier runs for all methods. 5 Future Work Recently, Yang et al. (2023) used the DeepProbLog system to integrate logical constraints in the training of Reinforcement Learning (RL) agents in subsymbolic environments. We believe NeSyA can aid in this direction, by allowing for the specification of more complicated temporal constraints, which require memory, i.e. some notion of state to be remembered from the execution of the environment so far, while being more scalable. A large class of systems is based on constraints for RL agents ( Alshiekh et al., 2018 ; Jansen et al., 2020 ) often using LTL. This seems a promising avenue for NeSyA which can extend such methods to subsymbolic RL domains. Further, NeSyA can be used to extend systems where automata are used to specify tasks and reward structures for RL agents ( Icarte et al., 2018 ) and their NeSy extension ( Umili et al., 2023a ) to incorporate logical transitions. Of significant interest is also the work of Ahmed et al. (2024) , who define a pseudo-semantic loss for autoregressive models with constraints and Zhang et al. (2023) , who similarly address the problem of incorporating constraints is LLMs. Both approaches assume a flat vocabulary. We believe NeSyA can be beneficial for constrained autoregressive models when the output structure includes many features, i.e. the model generates structured traces, instead of natural language. Perhaps the most natural avenue for future work is the definition of a high-level NeSy language for the specification of temporal programs which utilizes NeSyA as a compilation target. Automata are generally low-level devices, cumbersome to define by hand, motivating the creation of a human-centric interface. 6 Conclusion We presented the NeSyA system for integrating neural networks with symbolic automata, under clean probabilistic semantics. We showed that current systems, such as DeepStochLog , DeepProbLog , and FuzzyA struggle to achieve scalable and accurate solutions in temporal domains. The NeSyA system was instead shown to scale considerably better and achieve higher accuracy. 7