GenSQL: A Probabilistic Programming System for Querying Generative Models of Database Tables

Mathieu Huot, Matin Ghavami, Alexander K. Lew, Ulrich Schaechtle, Cameron E. Freer, Zane Shelby, Martin C. Rinard, Feras A. Saad, Vikash K. MansinghkaProc. ACM Program. Lang 2024 · DOI

TL;DR

This paper introduces GenSQL, a novel system that extends SQL to query probabilistic generative models of database tables. GenSQL allows users to seamlessly integrate complex probabilistic reasoning with standard database operations, enabling tasks like synthetic data generation, anomaly detection, and imputation with a declarative and concise syntax.

What Problem Does This Paper Address?

The increasing availability of probabilistic models for tabular data, learned through techniques like probabilistic program synthesis, has created a need for efficient ways to query and leverage these models. Existing probabilistic programming systems primarily focus on model specification and parameter estimation, lacking the expressiveness and integration capabilities required for complex database-style queries that interleave operations on tabular data and probabilistic models. This gap hinders the practical application of these models for tasks like generating realistic synthetic data, identifying anomalies, or imputing missing values in a way that respects the underlying probabilistic structure.

Methods

GenSQL extends SQL with a few key primitives to query probabilistic models. These include:

  • GENERATE UNDER m: For generating synthetic records from a probabilistic model m.
  • m GIVEN e: To condition a probabilistic model m on an event e (a set of constraints).
  • t GENERATIVE JOIN m: A mixed join clause to combine rows from a data table t with synthetic rows generated from a probabilistic model m, allowing per-row conditioning.
  • PROBABILITY OF e UNDER m: To compute the probability (or density) of an event e under a probabilistic model m.

The system is formalized with a novel type system and denotational semantics, ensuring correctness. A key component is the Abstract Model Interface (AMI), which provides a unifying specification for probabilistic models, allowing GenSQL to work with models implemented in various probabilistic programming languages (PPLs). GenSQL also features a query planner that lowers GenSQL queries to programs operating on this AMI, incorporating optimizations like caching and exploiting conditional independence.

Datasets

The paper evaluates GenSQL on two case studies:

  • Clinical trial data: Used for anomaly detection in COVID-19 related data.
  • Synthetic biology data: Used for conditional synthetic gene expression data generation for a virtual wet lab.

The paper also mentions using datasets from the UCI ML repository (Iris data) for code comparison.

Key Insights and Ideas

  • Bridging the gap between databases and probabilistic models: GenSQL's core innovation is providing a unified language and framework to query probabilistic models in a database-like fashion, making complex probabilistic reasoning accessible within familiar SQL paradigms.
  • Declarative querying for probabilistic models: The declarative syntax of GenSQL significantly simplifies expressing complex probabilistic queries, reducing the likelihood of programming errors compared to imperative approaches.
  • Flexibility through the Abstract Model Interface (AMI): The AMI allows GenSQL to be agnostic to the underlying PPL used to implement the probabilistic models, enabling multi-language workflows and the reuse of existing models.
  • Performance gains through optimizations: GenSQL achieves significant speedups (1.7-6.8x) over competitors due to optimizations like caching and exploiting conditional independence, making probabilistic queries practical.

Key Results

  • GenSQL demonstrates superior performance, achieving a 1.7-6.8x speedup compared to its closest competitor on representative benchmarks.
  • The system runs in comparable time to hand-written code, partly due to reusable optimizations.
  • Case studies show GenSQL more accurately captures data complexity in anomaly detection and synthetic data generation compared to baselines like generalized linear models (GLMs) and CTGANs.
  • The declarative syntax in GenSQL is shown to be more concise and less error-prone than alternatives.

Limitations and Future Work

  • Approximate inference guarantees: While GenSQL provides soundness theorems for both exact and approximate backends, the paper notes that for approximate inference, non-continuous operations (like indicator functions of half-intervals) can lead to queries that do not converge to the correct limit even as approximations improve. The paper introduces "safe" queries to mitigate this but acknowledges that this is a sufficient, not necessary, condition.
  • Future work: The authors suggest extending the AMI to handle synthesized models of time series and relational data, and exploring more permissive safety conditions for approximate queries. They also highlight the potential for integrating GenSQL directly into database management systems (DBMS) and enabling modularized development of queries and models.

Summary updated

BibTeX
@article{huot2024gensql,
  author = {Mathieu Huot and Matin Ghavami and Alexander K. Lew and Ulrich Schaechtle and Cameron E. Freer and Zane Shelby and Martin C. Rinard and Feras A. Saad and Vikash K. Mansinghka},
  title = {{GenSQL: A Probabilistic Programming System for Querying Generative Models of Database Tables}},
  journal = {Proc. ACM Program. Lang.},
  year = {2024},
  doi = {10.1145/3656409},
}
Figure