Query languages for neural networks
Martin Grohe, Christoph Standke, Juno Steegmans, Jan Van den Bussche
TL;DR
This work proposes two declarative query paradigms for neural networks: FO(R), a constraint-based black-box language over the reals, and FO(SUM), a white-box language over weighted network structures with summation. It shows that FO(SUM) can express model-agnostic and nontrivial queries beyond FO(R_linear), and, crucially, for networks of fixed depth ℓ, FO(SUM) can express every FO(R_linear) query, effectively enabling SQL-like verification of neural models. The main technical contribution is a translation framework that encodes piecewise-linear network functions via hyperplane arrangements and cylindrical decompositions, then simulates FO(R_linear) queries within FO(SUM) through a sequence of FO(SUM) translations. Together, these results establish a formal, database-inspired foundation for explainability, verification, and management of neural networks using declarative query languages, with potential integration into practical analytics and tooling for ML deployment pipelines.
Abstract
We lay the foundations for a database-inspired approach to interpreting and understanding neural network models by querying them using declarative languages. Towards this end we study different query languages, based on first-order logic, that mainly differ in their access to the neural network model. First-order logic over the reals naturally yields a language which views the network as a black box; only the input--output function defined by the network can be queried. This is essentially the approach of constraint query languages. On the other hand, a white-box language can be obtained by viewing the network as a weighted graph, and extending first-order logic with summation over weight terms. The latter approach is essentially an abstraction of SQL. In general, the two approaches are incomparable in expressive power, as we will show. Under natural circumstances, however, the white-box approach can subsume the black-box approach; this is our main result. We prove the result concretely for linear constraint queries over real functions definable by feedforward neural networks with a fixed number of hidden layers and piecewise linear activation functions.
