SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Francesco Giannini*
CINI, Italy
francesco.giannini@unisi.it
Stefano Fioravanti*
Universita di Siena, Italy, JKU Linz, Austria Italy stefano.fioravanti@unisi.it
Oguzhan Keskin
University of Cambridge, UK
ok313@cam.ac.uk
Alisia Maria Lupidi
aml201@cam.ac.uk
Lucie Charlotte Magister
1cm67@cam.ac.uk
pl219@cam.ac.uk
Pietro Barbiero*
Universita della Svizzera Italiana, CH
barbip@usi.ch
The rise of Artificial Intelligence (AI) recently empowered researchers to investigate hard mathematical problems which eluded traditional approaches for decades. Yet, the use of AI in Universal Algebra (UA)—one of the fields laying the foundations of modern mathematics—is still completely unexplored. This work proposes the first use of AI to investigate UA's conjectures with an equivalent equational and topological characterization. While topological representations would enable the analysis of such properties using graph neural networks, the limited transparency and brittle explainability of these models hinder their straightforward use to empirically validate existing conjectures or to formulate new ones. To bridge these gaps, we propose a general algorithm generating AI-ready datasets based on UA's conjectures, and introduce a novel neural layer to build fully interpretable graph networks. The results of our experiments demonstrate that interpretable graph networks: (i) enhance interpretability without sacrificing task accuracy, (ii) strongly generalize when predicting universal algebra's properties, (iii) generate simple explanations that empirically validate existing conjectures, and (iv) identify subgraphs suggesting the formulation of novel conjectures.
Universal Algebra (UA, (6)) is one of the foundational fields of modern Mathematics with possible deep impact in all mathematical disciplines, but the complexity of studying abstract algebraic structures hinders scientific progress and discourages many academics. Recently, the emergence of powerful AI technologies empowered researchers to investigate intricate mathematical problems which eluded traditional approaches for decades, leading to the solution of open problems (e.g., (24)) and discovery of new conjectures (e.g., (7)). Yet, universal algebra currently remains an uninvestigated realm for AI, primarily for two reasons (i) first
Figure 1: Interpretable graph networks support universal algebra research.
UA deals with infinite objects or even classes of abstract objects, which pose unique challenges for conventional AI techniques, (ii) secondly the field commonly relies on deterministic algorithms, utilized to construct finite models or serve as deterministic theorem provers, such as "mace4" and "prover9". In this sense, we hope that our paper could represent a guidance to further explore the study of UA's problems with AI, e.g. by integrating existing systems, like these mentioned theorem provers, with our methodology, which may suggest novel conjectures, in a unique scheme.
Universal algebra studies algebraic structures from an abstract perspective. Interestingly, several UA conjectures equivalently characterize algebraic properties using equations or graphs (16). In theory, studying UA properties as graphs would enable the use of powerful AI techniques, such as Graph Neural Networks (GNN, (39)), which excel on graph-structured data. However, two factors currently limit scientific progress. First, the absence of benchmark datasets suitable for machine learning prevents widespread application of AI to UA. Second, GNNs' opaque reasoning obstructs human understanding of their decision process (38). Compounding the issue of GNNs' limited transparency, GNN explainability methods mostly rely on brittle and untrustworthy local/post-hoc methods (14; 27; 28; 38; 45) or pre-defined subgraphs for explanations (2; 42), which are often unknown in UA.
Contributions. In this work, we investigate universal algebra's conjectures through AI (Figure 1). Our work includes three significant contributions. First, we propose a novel algorithm that generates a dataset suitable for training AI models based on an UA equational conjecture. Second, we generate and release the first-ever universal algebra's dataset compatible with AI, which contains more than 29,000 lattices and the labels of 5 key properties i.e., modularity, distributivity, semi-distributivity, join semi-distributivity, and meet semi-distributivity. And third, we introduce a novel neural layer that makes GNNs fully interpretable, according to Rudin's (38) notion of interpretability. The results of our experiments demonstrate that interpretable GNNs (iGNNs): (i) enhance GNN interpretability without sacrificing task accuracy, (ii) strongly generalize when trained to predict universal algebra's properties, (iii) generate simple concept-based explanations that empirically validate existing conjectures, and (iv) identify subgraphs which could be relevant for the formulation of novel conjectures. As a consequence, our findings demonstrate the potentiality of AI methods for investigating UA problems.
Universal Algebra is a branch of mathematics studying general and abstract algebraic structures. Algebraic structures are typically represented as ordered pairs  $\mathbf{A} = (A,F)$ , consisting of a non-empty set  $A$  and a collection of operations  $F$  defined on the set. UA aims to identify algebraic properties (often in equational form) shared by various mathematical systems. In particular, varieties are classes of algebraic structures sharing a common set of identities, which enable the study of algebraic systems based on their common properties. Prominent instances of varieties that have been extensively studied across various academic fields encompass Groups, Rings, Boolean Algebras, Fields, and many others. A particularly relevant variety of algebras are Lattices (details in Appendix A.3), which are often studied for their connection with logical structures.
Definition 2.1. A lattice  $\mathbf{L}$  is an algebraic structure composed by a non-empty set  $L$  and two binary operations  $\vee$  and  $\wedge$ , satisfying the commutativity, associativity, idempotency, and absorption axioms.
Equivalently a lattice can be characterized as a partially ordered set in which every pair of elements has a supremum  $(\vee)$  and an infimum  $(\wedge)$  (cf. Appendix A.3). Lattices also have formal representations as graphs via Hasse diagrams  $(L, E)$  (e.g., Figure 2), where each node  $x \in L$  is a lattice element, and directed edges  $(x, y) \in E \subseteq L \times L$  represent the ordering relation, such that if  $(x, y) \in E$  then  $x \leq_L y$  in the ordering of the lattice. A sublattice  $\mathbf{L}'$  of a lattice  $\mathbf{L}$  is a lattice such that  $L' \subseteq L$  and
Figure 2: Hasse diagrams.
$\mathbf{L}'$  preserves the original order (the "essential structure") of  $L$ , i.e. for all  $x, y \in L'$  then  $x \leq_{L'} y$  if and only if  $x \leq_L y$ . The foundational work by Birkhoff (5), Dedekind (9), and Jónsson (18) played a significant role in discovering that some significant varieties of lattices can be characterized through the omission of one or more lattices. Specifically, a variety  $\mathcal{V}$  of lattices is said to omit a lattice  $\mathbf{L}$  if the latter cannot be identified as a sublattice of any lattice in  $\mathcal{V}$ . A parallel line of work in UA
1https://www.cs.unm.edu/~mccune/prover9/.
2The orientation of Hasse diagrams is always to be meant bottom-up, hence we will omit arrows for simplicity.
characterizes lattices in terms of equational ("term  $1 \approx$  term  $2$ " ) and quasi-equational ("if equation  $1$  holds then equation  $2$  holds") properties, such as distributivity and modularity.
Definition 2.2. Let  $\mathbf{L}$  be a lattice.  $\mathbf{L}$  is modular if it satisfies  $x\leq y\to x\vee (y\wedge z)\approx y\wedge (x\vee z)$  distributive if it satisfies  $x\vee (y\wedge z)\approx (x\vee y)\wedge (x\vee z)$
We notice that each distributive lattice is also modular (see Appendix A.3). Figure 2 represents  $\mathbf{M}_3$  (modular with 3 atoms) and  $\mathbf{N}_5$  (non-modular with 5 atoms), the smallest instances of lattices which exhibit failures of distributivity and modularity, respectively. For example,  $\mathbf{N}_5$  is neither modular nor distributive, considering the substitution  $x = a$ ,  $y = c$ ,  $z = b$ . The same substitution shows that  $\mathbf{M}_3$  is not distributive. The classes of distributive and modular lattices show classical examples of varieties that can equivalently be characterized using equations and lattice omissions, as illustrated by the following theorems.
Theorem 2.3 (Dedekind (9)). A lattice variety  $\mathcal{V}$  is modular if and only if  $\mathcal{V}$  omits  $\mathbf{N}_5$ .
Theorem 2.4 (Birkhoff (5)). A lattice variety  $\mathcal{V}$  is distributive if and only if  $\mathcal{V}$  omits  $\mathbf{N}_5$  and  $\mathbf{M}_3$ .
Starting from these classic results, the investigation of lattice omissions and the structural characterizations of classes of lattices has evolved into a rich and extensively studied field (16), but it was never approached with AI methodologies before.
The problem of characterizing lattice varieties through lattice omission is very challenging as it requires the analysis of large (potentially infinite) lattices (5; 9; 18). To address this task, we propose the first AI-assisted framework supporting mathematicians in finding empirical evidences to validate existing conjectures and to suggest novel theorems. To this end, we propose a general algorithm (Section 3.1) allowing researchers in universal algebra to define a property of interest and generate a dataset suitable to train AI models. We then introduce interpretable graph networks (Section 3.2) which can suggest candidate lattices whose omission is responsible for the satisfaction of the given algebraic property.
3.1 A Tool to Generate Datasets of Lattice Varieties
We propose a general methodology to investigate any algebraic property whose validity can be verified on a finite lattice. In this work, we focus on properties that can be characterized via equations and quasi-equations. To train AI models, we propose a general dataset generator for lattice varieties. Intuitively, the generator takes as input the number of nodes  $n$  in the lattices and a function to check whether a lattice satisfies a given property. We generate  $2^{n \times n}$  matrices of size  $n \times n$ , containing all binary functions
Algorithm 1: Generate dataset of lattice varieties.  
Input:  $n \geq 1$ , hasProperty( $.,\cdot$ ) //  $n$ : cardinality  
Dataset = []  
AllFuncs ← genAllFuncs(n) // binary functions as  $n \times n$  matrices  
for  $L \in \text{AllFuncs}$  do //  $L(i,j) = 1$  meaning  $i \leq_L j$   
if isPartialOrder(L) then // check if  $\leq_L$  is refl., antisym. and trans.  
if isLattice(L) then // check if  $L$  is a lattice  
for  $i,j \leq n$  do  
 $\wedge_L[i,j] \gets \sup_{x \leq_L} \{ x \leq_L i$  and  $x \leq_L j \}$ $\vee_L[i,j] \gets \inf_{x \leq_L} \{ i \leq_L x$  and  $j \leq_L x \}$   
if hasProperty(L,  $\wedge_L, \vee_L$ ) then // check  $\wedge_L, \vee_L$  properties  
Dataset.append([L, True])  
else  
Dataset.append([L, False])
definable on  $\{1, \ldots, n\}^2$ , and filter only binary matrices representing partial orders. Then, we verify that the partial ordered set  $L$  is a lattice, by checking that any pair of nodes always has a unique infimum and supremum. This directly verifies that  $\wedge_L$  and  $\vee_L$  satisfy Definition 2.1. Finally, we check whether the lattice satisfies the target property or not, and append it and the property label to our dataset. We remark that checking the validity of a single ternary equation on a medium-size lattice is not computationally prohibitive (i.e., it "only" requires checking  $n^3$  identities), but the number of existing lattices increases exponentially as  $n$  increases. For instance, it is known that there are at least 2,000,000 non-isomorphic lattices with  $n = 10$  elements (4). Therefore, we only sample a fixed number of lattices per cardinality starting from a certain node cardinality. While this may seem a strong bias, we notice that known and relevant lattice omissions often rely on lattices with few nodes (5; 9). To empirically verify that this is not a significant limitation, in our experiments we deliberately investigate the generalization capacity of GNNs when trained on small-size lattices and tested on larger ones. This way we can use GNNs to predict the satisfiability of equational properties
<sup>3</sup>The dataset generator and the datasets are available at https://github.com/fragiannini/AI4UA.
Figure 3: An interpretable graph layer (i) aggregates node features with message passing, (ii) generates a node-level concept space with a hard Gumbel-Softmax activation  $\Theta$ , (iii) generates a graph-level concept space with an interpretable permutation invariant pooling function  $\boxplus$  on node-level concepts, and (iv) predicts a task label with an interpretable classifier  $f$  using graph-level concepts.
on large graph structures without explicitly checking them. Using Algorithm 1, we generated the first large-scale AI-compatible datasets of lattices containing more than 29,000 graphs and the labels of 5 key properties of lattice (quasi-)varieties i.e., modularity, distributivity, semi-distributivity, join semi-distributivity, and meet semi-distributivity, whose definitions can be found in Appendix A.
Scalability and Complexity. The scalability of the dataset generation process is related to two main points: (i) dealing with the exponential growth of the number of lattices, (ii) how to feasibly generate a lattice of a finite amount of elements. (i) Since the number of lattices definable on a set  $L = \{0, \dots, n - 1\}$  increases exponentially with  $n$ , it is not feasible to realize a dataset containing all the lattices of  $n$  elements. However, this is also unnecessary for the scope of this work, which aims at automatically identifying (small) topological patterns responsible for the failure of certain algebraic properties. In addition, the majority of the graphs generated are isomorphic, thus not particularly informative for our task. Because of this, we only generate a portion of all the lattices up to a certain value  $M > 0$ , and then take a fixed number of samples  $n_s$  up to  $N$  (we take  $M = 8$ ,  $n_s = 20$ ,  $N = 50$  in the paper). (ii) The construction of a lattice with  $n$  elements is briefly sketched in Algorithm 1. We refer to Appendix B for the technical details on the design of the used functions.
3.2 Interpretable Graph Networks (iGNNs)
In this section, we design an interpretable graph network (iGNN, Figure 3) that satisfies the notion of "interpretability" introduced by Rudin (38). According to this definition, a machine learning (ML) system is interpretable if and only if (1) its inputs are semantically meaningful, and (2) its model inference is simple for humans to understand (e.g., sparse and/or symbolic). This definition covers ML systems that take tabular datasets or sets of concepts as inputs, and (piece-wise) linear models such as logistic regression or decision trees. To achieve this goal in GNNs, we introduce an interpretable graph layer that learns semantically meaningful concepts and uses them as inputs for a simple linear classification layer. We then show how this layer can be included into existing architectures or into hierarchical iGNNs, which consist of a sequence of interpretable graph layers. We notice that in devising our approach, we preferred to rely on linear classifiers as they are fully differentiable, hence allowing us to realize a fully interpretable and differentiable model from the input to the classification head. However, in practice any interpretable and differentiable classifier could be used in place of this linear layer.
3.2.1 Interpretable Graph Layer
The interpretable graph layer (Figure 3) serves three main functions: message passing, concept generation, and task predictions. The first step of the interpretable graph layer involves a standard message passing operation (Eq. 1 right), which aggregates information from node neighbors. This operation enables to share and process relational information across nodes and it represents the basis of any GNN layer.
Node-level concepts. An interpretable concept space is the first step towards interpretability. Following Ghorbani et al. (10), a relevant concept is a "high-level human-understandable unit of
information" shared by input samples and thus identifiable with clustering techniques. Message passing algorithms do cluster node embeddings based on the structure of node neighborhoods, as observed by Magister et al. (28). However, the real-valued large embedding representations  $\mathbf{h}_i\in \mathbb{R}^q,q\in \mathbb{N}$  generated by message passing can be challenging for humans to interpret. To address this, we use a hard Gumbel-Softmax activation  $\Theta :\mathbb{R}^q\mapsto \{0,1\} ^q$  , following Azzolin et al. (2):
$$
\mathbf {c} _ {i} = \Theta (\mathbf {h} _ {i}) \quad \mathbf {h} _ {i} = \phi \left(\mathbf {x} _ {i}, \bigoplus_ {j \in N _ {i}} \psi \left(\mathbf {x} _ {i}, \mathbf {x} _ {j}\right)\right) \tag {1}
$$
where  $\psi$  is a learnable function ignoring or assuming constant input features and  $\phi$  is a learnable function aggregating information from a node neighborhood  $N_{i}$ , and  $\oplus$  is a permutation invariant aggregation function (such as sum or mean). During the forward pass, the Gumbel-Softmax activation  $\Theta$  produces a one-hot encoded representation of each node embedding. Since nodes sharing the same neighborhood have similar embeddings  $\mathbf{h}_i$  due to message passing, they will also have the same one-hot vector  $\mathbf{c}_i$  due to the Gumbel-Softmax, and vice versa - we can then interpret nodes having the same one-hot concept  $\mathbf{c}_i$  as nodes having similar embeddings  $\mathbf{h}_i$  and thus sharing a similar neighborhood. More formally, we can assign a semantic meaning to a reference concept  $\gamma \in \{0,1\}^q$  by visualizing concept prototypes corresponding to the inverse images of a node concept vector. In practice, we can consider a subset of the input lattices  $\Gamma$  corresponding to the node's  $(p$ -hop) neighborhood covered by message passing:
$$
\Gamma (\gamma , p) = \left\{\mathbf {L} ^ {\langle i, p \rangle} \mid i \in L \wedge \mathbf {L} \in \mathcal {D} \wedge \mathbf {c} _ {i} = \gamma \right\} \tag {2}
$$
where  $\mathcal{D}$  is the set of all training lattices, and  $\mathbf{L}^{\langle i,p\rangle}$  is the graph corresponding to the  $p$ -hop neighborhood  $(p\in \{1,\dots ,|L|\})$  of the node  $i\in L$ , as suggested by Ghorbani et al. (10); Magister et al. (28). This way, by visualizing concept prototypes as subgraph neighborhoods, the meaning of the concept representation becomes easily interpretable to humans (Figure 3), aiding in the understanding of the reasoning process of the network.
Example 3.1 (Interpreting node-level concepts). Consider the problem of classifying distributive lattices with a simplified dataset including  $\mathbf{N}_5$  and  $\mathbf{M}_3$  only, and where each node has a constant feature  $x_i = 1$ . As these two lattices only have nodes with 2 or 3 neighbours, one layer of message passing will then generate only two types of node embeddings e.g.,  $\mathbf{h}_{II} = [0.2, -0.4, 0.3]$  for nodes with a 2-nodes neighborhood (e.g.,  $\diamond$ ), and  $\mathbf{h}_{III} = [0.6, 0.2, -0.1]$  for nodes with a 3-nodes neighborhood (e.g.,  $\diamond$ ). As a consequence, the Gumbel-Softmax will only generate two possible concept vectors e.g.,  $\mathbf{c}_{II} = [0, 0, 1]$  and  $\mathbf{c}_{III} = [1, 0, 0]$ . Hence, for instance the concept belongs to  $\mathbf{c}_{II}$ , while  $\diamond$  belongs to  $\mathbf{c}_{III}$ .
Graph-level concept embeddings. To generate a graph-level concept space in the interpretable graph layer, we can utilize the node-level concept space produced by the Gumbel-Softmax. Normally, graph-level embeddings are generated by applying a permutation invariant aggregation function on node embeddings. However, in iGNNs we restrict the options to (piece-wise) linear permutation invariant functions in order to follow our interpretability requirements dictated by Rudin (38). This restriction still includes common options such as max or sum pooling. Max pooling can easily be interpreted by taking the component-wise max over the one-hot encoded concept vectors  $\mathbf{c}_i$ . After max pooling, the graph-level concept vector has a value of 1 at the  $k$ -th index if and only if at least one node activates the  $k$ -th concept i.e.,  $\exists i \in L, \mathbf{c}_{ik} = 1$ . Similarly, we can interpret the output of a sum pooling: a graph-level concept vector takes a value  $v \in \mathbb{N}$  at the  $k$ -th index after sum pooling if and only if there are exactly  $v$  nodes activating the  $k$ -th concept i.e.,  $\exists i_0, \dots, i_v \in L, \mathbf{c}_{ik} = 1$ .
Example 3.2 (Interpreting graph-level concepts). Following Example 3.1, let us use sum pooling to generate graph-level concepts. For an  $\mathbf{N}_5$  graph, we have 5 nodes with exactly the same 2-node neighborhood. Therefore, sum pooling generates a graph-level embedding  $[0,0,5]$ , which certifies that we have 5 nodes of the same type e.g.,  $\diamond$ . For an  $\mathbf{M}_3$  graph, the top and bottom nodes have a 3-node neighborhood e.g.,  $\diamond$ , while the middle nodes have a 2-node neighborhood e.g.,  $\diamond$ . This means that sum pooling generates a graph-level embedding  $[2,0,3]$ , certifying that we have 2 nodes of type  $\diamond$  and 3 nodes of type  $\diamond$ .
Interpretable classifier. To prioritize the identification of relevant concepts, we use a classifier to predict the task labels using the concept representations. A black-box classifier like a multi-layer perceptron (36) would not be ideal as it could compromise the interpretability of our model, so instead we use an interpretable linear classifier such as a single-layer network (20). This allows for a completely interpretable and differentiable model from the input to the classification head, as the input representations of the classifier are interpretable concepts and the classifier is a simple linear model which is intrinsically interpretable as discussed by Rudin (38). In fact, the weights of the perceptron can be used to identify which concepts are most relevant for the classification task. Hence, the resulting model can be used not only for classification, but also to interpret and understand the problem at hand.
3.2.2 Interpretable architectures
The interpretable graph layer can be used to instantiate different types of iGNNs. One approach is to plug this layer as the last message passing layer of a standard GNN architecture:
$$
\hat {y} = f \left(\boxplus_ {i \in K} \left(\Theta \left(\phi^ {(K)} \left(\mathbf {h} _ {i} ^ {(K - 1)}, \bigoplus_ {j \in N _ {i}} \psi^ {(K)} \left(\mathbf {h} _ {i} ^ {(K - 1)}, \mathbf {h} _ {j} ^ {(K - 1)}\right)\right)\right)\right)\right) \tag {3}
$$
$$
\mathbf {h} _ {i} ^ {(l)} = \phi^ {(l)} \left(\mathbf {h} _ {i} ^ {(l - 1)}, \bigoplus_ {j \in N _ {i}} \psi^ {(l)} \left(\mathbf {h} _ {i} ^ {(l - 1)}, \mathbf {h} _ {j} ^ {(l - 1)}\right)\right) \quad l = 1, \dots , K \tag {4}
$$
where  $f$  is an interpretable classifier (e.g., single-layer network),  $\boxplus$  is an interpretable piece-wise linear and permutation-invariant function (such as max or sum),  $\Theta$  is a Gumbel-Softmax hard activation function, and  $\mathbf{h}_i^0 = \mathbf{x}_i$ . In this way, we can interpret the first part of the network as a feature extractor generating well-clustered latent representations from which concepts can be extracted. This approach is useful when we only care about the most complex neighborhoods/concepts. Another approach is to generate a hierarchical transparent architecture where each GNN layer is interpretable:
$$
\hat {y} ^ {(l)} = f \left(\boxplus_ {i \in K} \left(\Theta \left(\mathbf {h} _ {j} ^ {(l)}\right)\right)\right) \quad l = 1, \dots , K \tag {5}
$$