Learning Deterministic Weighted Automata with Queries and Counterexamples

Gail Weiss, Yoav Goldberg, Eran Yahav

This paper introduces a novel method for extracting interpretable, state-based models from "black-box" neural networks. Specifically, it focuses on distilling Recurrent Neural Networks (RNNs) into Probabilistic Deterministic Finite Automata (PDFAs).

TL;DR

The authors adapt the classic $L^*$ active learning algorithm to extract PDFAs from trained RNNs. By introducing a "variation tolerance" to handle the continuous nature of neural states, they create a method that produces interpretable, fast, and stochastic models that frequently outperform traditional spectral extraction methods.

The Problem: Unboxing the RNN

RNNs (like LSTMs and GRUs) are incredibly powerful for sequence modeling, but they are notorious "black boxes." While they perform well, their internal logic and the states they use to make decisions remain opaque.

While researchers have previously extracted simple "binary" automata (which just output yes/no for a given string), extracting probabilistic models—which predict the likelihood of the next token—is significantly harder. Existing methods for this typically face one of three pitfalls:

  1. Require massive amounts of data (passive learning).
  2. Produce non-deterministic models (WFAs) that are slower to execute and harder for humans to interpret.
  3. Fail to guarantee "stochasticity" (meaning the predicted probabilities might not sum to 1).

The authors sought a way to "distill" the logic of an RNN into a clean, state-transition table that is both human-readable and mathematically sound.

Methods: Adapting the $L^*$ Algorithm

The researchers built their approach on Angluin’s $L^*$ algorithm, a foundational technique in automata theory that learns a model by asking an "oracle" (in this case, the RNN) two types of questions:

  1. Membership Queries: "What is the probability of the next token given this prefix?"
  2. Equivalence Queries: "Is this PDFA I built a good enough approximation of you?" (If not, the RNN provides a counterexample).

The "Secret Sauce": Variation Tolerance ($t$-equality)

The primary challenge in applying discrete logic to neural networks is that RNN states are continuous vectors. You will almost never find two prefixes that result in exactly the same probability distribution.

To solve this, the authors introduced $t$-equality. They treat two states as identical if the difference between their predicted probabilities is less than a tolerance $t$. Because this "similarity" isn't transitive (if A is similar to B, and B is similar to C, A might not be similar to C), they developed a specialized 4-step clustering algorithm to partition the state space into "cliques" that maintain determinism.

Datasets

The algorithm was evaluated on several synthetic but complex language benchmarks:

  • SPiCe Competition Grammars: 10 different grammars covering domains like NLP, software code, and biology.
  • Tomita Grammars: A classic set of 7 benchmark languages used in formal language theory.
  • UHLs (Unbounded History Languages): Three new languages introduced by the authors specifically designed to require "memory" that goes beyond a simple fixed window (where $n$-gram models typically fail).

Key Insights

  • Conditional Probabilities are Key: Instead of looking at the total probability of a long string (which vanishes toward zero), the algorithm queries the conditional probability of the last token. This keeps the "signal" strong regardless of sequence length.
  • Interpretability vs. Efficiency: A PDFA is essentially a lookup table. Unlike an RNN, which requires matrix multiplications for every step, a PDFA simply follows a pointer to the next state. This makes them significantly faster for inference.
  • Anytime Extraction: The authors designed the algorithm so it can be stopped at any time. Even if it hasn't perfectly "solved" the RNN, it provides a model that is guaranteed to be consistent with all the observations made up to that point.

Key Results

Performance comparison on SPiCe datasets
  • Superior Accuracy: Their algorithm (WL*) consistently achieved lower Word Error Rates (WER) and better Normalized Discounted Cumulative Gain (NDCG) than spectral learning methods across various SPiCe datasets.
  • Perfect Reconstruction: On the UHL and Tomita datasets, the algorithm was often able to perfectly reconstruct the underlying structure of the target language.
  • Beating $n$-grams: While $n$-gram models are very strong on languages with "local" properties, they failed completely on the Unbounded History Languages. WL* handled both local and unbounded dependencies effectively.
  • Model Size: The extracted PDFAs were often quite compact (ranging from a few states to a few thousand), providing a much simpler representation than the thousands of weights in an LSTM.

Limitations and Future Work

  • The "Oracle" Problem: In the real world, we don't have a perfect "Equivalence Query." The authors had to approximate this by sampling the RNN, meaning there is always a small chance a counterexample is missed.
  • Scaling to Natural Language: While successful on synthetic grammars, the number of states required for a full natural language (like English) might explode, making the observation table unmanageable.
  • Transformers: The authors note that while the algorithm is "model-agnostic," the analogy of a PDFA (which processes tokens one-by-one) fits RNNs much better than it fits the parallel architecture of Transformers. Exploring how to bridge this gap remains an open challenge for future work.

Summary updated

BibTeX
@inproceedings{weiss2019learning,
  author = {Gail Weiss and Yoav Goldberg and Eran Yahav},
  title = {{Learning Deterministic Weighted Automata with Queries and Counterexamples}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2019},
}
Figure