TensorLog: A Differentiable Deductive Database

William W. CohenarXiv 2016

Abstract

Large knowledge bases (KBs) are useful in many tasks, but it is unclear how to integrate this sort of knowledge into "deep" gradient-based learning systems. To address this problem, we describe a probabilistic deductive database, called TensorLog, in which reasoning uses a differentiable process. In TensorLog, each clause in a logical theory is first converted into certain type of factor graph. Then, for each type of query to the factor graph, the message-passing steps required to perform belief propagation (BP) are "unrolled" into a function, which is differentiable. We show that these functions can be composed recursively to perform inference in non-trivial logical theories containing multiple interrelated clauses and predicates. Both compilation and inference in TensorLog are efficient: compilation is linear in theory size and proof depth, and inference is linear in database size and the number of message-passing steps used in BP. We also present experimental results with TensorLog and discuss its relationship to other first-order probabilistic logics.

Introduction

Deep learning has revolutionized pattern recognition, yet it often struggles with structured, multi-step reasoning. Conversely, Knowledge Bases (KBs) and Deductive Databases (DDBs) excel at representing complex relationships but are difficult to integrate into gradient-based learning pipelines. The fundamental challenge lies in the nature of logical inference: it is typically a discrete search process, making it incompatible with standard backpropagation.

TensorLog addresses this by transforming logical reasoning into a series of differentiable matrix operations. By "unrolling" belief propagation into a computation graph, it enables efficient, gradient-based learning over large-scale knowledge bases while preserving the formal structure of first-order logic.

The TensorLog Framework

TensorLog bridges symbolic logic and neural networks through a three-stage process: conversion, compilation, and numeric encoding.

Factor Graph Conversion

Each clause in a logical theory—specifically function-free Horn clauses—is converted into a factor graph. In this representation, logical variables are treated as random variables, and literals (predicates) serve as factors. This mapping allows the system to treat logical proofs as probabilistic inference problems.

Conversion of logical clauses into factor graphs for the 'uncle' and 'status' predicates.

Compiling Inference

For a specific query, the message-passing steps required for Belief Propagation (BP) are "unrolled" into a fixed sequence of operations. This compilation process is recursive, allowing TensorLog to handle complex theories with interrelated clauses.

Recursive compilation of message-passing steps into differentiable operations.

Numeric Encoding and Differentiability

The database is represented numerically: constants are one-hot vectors ($u_c$), unary predicates are vectors ($v_q$), and binary predicates are sparse matrices ($M_p$). Because the resulting "reasoning function" consists entirely of standard linear algebra operations—such as sparse matrix-vector multiplication and Hadamard products—the entire inference process is differentiable. This allows for backpropagation through logical proofs to learn parameters ($\Theta$) that define the confidence of facts.

Experimental Evaluation

TensorLog was evaluated across several benchmarks to test its speed, scalability, and learning capabilities:

  • Social Influence: A "friends and smokers" model on the Citeseer network.
  • Path-finding: Recursive transitive closures on grids up to 64x64.
  • Knowledge Base Completion: Tasks on Cora (13k facts), Wordnet (276k facts), and Freebase15k (923k facts).

Key Results

  • Efficiency: On the Social Influence task, TensorLog processed a 3,327-node network in 0.84ms, whereas traditional engines like ProbLog2 took significantly longer on much smaller graphs.
  • Scalability: It performed deep recursive path-finding on a 64x64 grid in just 5.4ms.
  • Accuracy: TensorLog achieved competitive AUC scores, such as 93.3% on Wordnet Hypernyms, comparable to state-of-the-art systems like ProPPR.
  • Learning: In grid-world experiments, the system successfully learned to approximate complex distributions, improving accuracy from 0% to 96.5% by training on underlying grid edges.

Discussion and Future Work

TensorLog demonstrates that logical inference can be viewed as a static computation graph rather than a search tree. By utilizing sparse matrix representations, it maintains millisecond-level inference times even with nearly a million facts. While it uses a "tuple independence" approximation to ensure tractability, this trade-off enables practical scalability for modern machine learning tasks.

Current limitations include syntactic restrictions to unary and binary predicates and the requirement for tree-structured factor graphs. Future work will focus on tighter integration with non-logical deep learning architectures and leveraging GPU parallelization to further enhance performance.

Summary updated

BibTeX
@misc{cohen2016tensorlog,
  author = {William W. Cohen},
  title = {{TensorLog: A Differentiable Deductive Database}},
  year = {2016},
  eprint = {1605.06523},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1605.06523},
}
Figure