Abstract
This paper introduces Nester (NEuro-Symbolic consTrainEd structuRed predictor), a framework that integrates deep learning's perceptual power with the logical rigor of constraint programming. While standard neural networks excel at mapping raw data to symbols, they often fail to respect the underlying structural rules of complex outputs, such as mathematical equations. Nester addresses this by adding a symbolic refinement layer that enforces hard algebraic and logical constraints. Evaluated on handwritten equation recognition, Nester achieves an 82.9% relative error reduction over baseline models and demonstrates exceptional data efficiency by leveraging background knowledge as a regularizer.
Introduction
In structured prediction, the goal is to predict complex, interdependent objects like parse trees or mathematical equations. While deep learning models are highly effective at "perception"—transforming raw pixels into individual symbols—they frequently struggle with the "logic" of the output. For instance, a Convolutional Neural Network (CNN) might correctly identify digits but predict an invalid equation like "$4 + 2 = 7$". Existing neuro-symbolic approaches often rely on "fuzzy logic" or satisfy constraints only on average, which is insufficient for tasks requiring hard guarantees of mathematical or syntactic validity.
Methods: The Nester Architecture
Nester operates through a two-stage process designed for end-to-end training:
- Neural Component: A CNN processes raw input images (e.g., handwritten characters) to generate initial "raw" predictions. This component is initially "constraint-blind," predicting each symbol independently based on visual features.
- Symbolic Refinement Layer: This layer treats the raw predictions as an optimization problem. Using the MiniZinc constraint modeling language and the Gurobi solver, it identifies the optimal output that satisfies a set of hard constraints (e.g., valid equation syntax and mathematical correctness) and soft constraints (weighted features that keep the output close to the neural network's original estimate).
The entire system is trained end-to-end using stochastic sub-gradient descent. This allows the loss from the symbolic solver to backpropagate into the CNN, encouraging the neural network to learn features that are more compatible with the eventual structural requirements.
Experimental Setup
The model was evaluated on a handwritten equation recognition task using 10,000 valid equations from the ICFHR’14 CROHME competition. The task involved images of equations in the format $a + b = c$, where $a, b, c$ are multi-digit integers. This task is significantly more complex than standard MNIST-addition because the number of digits is variable and the positions of operators ($+$ and $=$) are not fixed, creating a vast search space.
Key Results and Insights
Nester demonstrated a clear advantage over both pure neural models and other neuro-symbolic frameworks:
- Error Reduction: By the end of training, Nester achieved an 82.9% relative error reduction compared to a standalone CNN.
- Data Efficiency: The performance gap was most pronounced when training data was scarce. Nester’s ability to inject "background knowledge" (the rules of arithmetic) serves as a powerful regularizer, allowing it to perform well even with limited examples.
- Semantic vs. Syntactic Learning: Analysis showed that while neural networks (including LSTMs) eventually learn the syntax of equations (e.g., where to place the $+$ sign), they struggle to learn the semantics (the actual math). Nester bridges this "semantic gap" by enforcing mathematical correctness through its solver.
Compared to DeepProbLog, Nester scaled much more effectively. DeepProbLog became computationally and memory-intensive due to the high degree of non-determinism in variable-length equations, whereas Nester’s constraint-programming approach handled the search space efficiently.
Limitations and Future Work
Despite its success, Nester has some limitations. The inference time is dominated by the constraint solver, taking nearly a second per equation, which may be too slow for real-time applications. Additionally, the model assumes that the provided constraints are perfectly accurate; incorrect rules would lead to incorrect predictions. Future research will focus on approximation techniques to speed up inference and methods to automatically learn constraints from data rather than relying on manual MiniZinc modeling.
Summary updated