Learning of Tree Automata applied to Neural Language Acceptors

Juan Pedro da Silva, Sergio YovinearXiv 2026 · arXiv

TL;DR

This paper introduces a fully black-box method for extracting symbolic "visibly pushdown grammars" (VPGs) from neural language models, including Transformers. By replacing internal-state-dependent search with tree-based PAC sampling and introducing a "hybrid" membership policy, the authors can now detect and characterize how neural models behave when faced with malformed, non-grammatical inputs.

What Problem Does This Paper Address?

Neural language models are notoriously opaque. While they can achieve high accuracy on structured tasks like parsing arithmetic or code, we often don't know what rules they have actually learned. Grammatical inference aims to solve this by extracting a symbolic surrogate model—like a Deterministic Finite Automaton (DFA)—that we can inspect and verify.

However, many interesting languages (like those with nested parentheses) are not "regular" and cannot be captured by DFAs. They require Visibly Pushdown Languages (VPLs). The existing state-of-the-art framework, VPL*, had two major flaws:

  1. White-box dependency: It required access to a model's internal states and a recurrent architecture to perform an A* search for counterexamples. This makes it incompatible with modern Transformers.
  2. "Gated" blindness: It only queried the neural model on "well-formed" inputs. If a neural model incorrectly accepted a malformed string (e.g., ())), the learner would never know, leading to an incomplete picture of the model's true behavior.

Methods

The authors propose three key improvements to the VPL* framework:

  • Black-Box Equivalence via PAC Sampling: Instead of searching through internal network states, they use a Probably Approximately Correct (PAC) oracle. This oracle samples trees from a distribution to find cases where the current symbolic hypothesis disagrees with the neural target. This allows the method to work on any binary acceptor, including Transformers.
  • Tree Encoding: The system works by lifting strings into a tree representation called BParse. As shown in Figure 1, push operations (like opening a bracket) become binary nodes, while pops become unary nodes.
Figure 1: The encoding φ(aabb) = a(a(□, b(□)), b(□)) of the Dyck-1 word aabb. Each push letter becomes a binary node carrying its matched pop as the right child; each pop is a unary node; leaves □stand for the empty word.
  • The Hybrid Membership Policy: The authors categorized inputs into three classes:
  • Class A: Well-formed trees (the "happy path").
  • Class B: Trees that aren't well-formed but represent a string that is well-formed (redundant data).
  • Class C: Trees representing ill-matched, non-grammatical sequences.

While the original "Gated" policy (Figure 2) simply returned false for anything not in Class A, the new Hybrid Policy (Figure 4) queries the neural model for Class C inputs. This allows the learner to see "leakage"—instances where the neural model incorrectly accepts invalid strings.

The hybrid membership policy. Class C queries the target directly to find leakage witnesses.

Datasets

The researchers evaluated their approach on three target families:

  1. VPG Targets: 15 standard visibly pushdown languages used in prior literature to ensure the new black-box method maintains parity with the old white-box one.
  2. Synthetic Non-VPL Targets: Specifically designed "broken" targets (e.g., a model that accepts everything or a model that accepts Dyck-1 strings with an extra prefix) to test the leakage detector.
  3. Neural Transformer: A bidirectional transformer trained on the Dyck-1 language (balanced parentheses).

Key Insights and Ideas

  • Sampling Trees vs. Sequences: A crucial realization was that when dealing with malformed inputs (Class C), the mapping from strings to trees becomes many-to-one. To maintain a consistent observation table for the learner, the equivalence oracle must sample trees directly rather than sampling strings and converting them.
  • Leakage as a Refutation: The "leakage witnesses" (Class C strings accepted by the model) serve as concrete proof that the neural model has not perfectly learned a VPL.
  • Structural Fingerprinting: By analyzing which types of malformed strings a model accepts (e.g., "excess close" vs. "excess open"), researchers can gain a "structural fingerprint" of the model's failures.

Key Results

  • Transformer Extraction: The method successfully extracted a 2-state VPG from a bidirectional Transformer, marking a successful application of VPL* to non-recurrent, black-box architectures.
  • Discovery of Hidden Behaviors: On the Transformer target, the hybrid learner issued 154x more probes and found 289x more witnesses of incorrect behavior than the gated learner.
  • DTA Complexity: While the final extracted VPGs were often simple, the underlying Deterministic Tree Automata (DTA) grew significantly larger under the hybrid policy (e.g., 53 states vs 2 states). This shows the hybrid policy captures a much richer, albeit messier, picture of the neural model's internal logic.

Limitations and Future Work

  • Non-Minimal Models: The extracted VPGs are not necessarily minimal. Unlike regular languages, VPLs do not always have a unique minimal automaton, making simplification difficult.
  • Computational Cost: Sampling trees for Transformers is expensive. The authors had to limit sample sizes and tree depths for the Transformer experiments due to the cost of the forward pass.
  • Generalization: While the gated and hybrid VPGs agreed on all tested well-formed strings, the authors note they haven't yet proven that this equivalence holds mathematically for all possible cases.

Summary updated

Abstract

We extract visibly pushdown grammars (VPGs) from neural language models in a fully black-box setting. Our work builds on the VPL* framework, which learns VPGs from recurrent networks by exploiting access to the target's internal state. First, we replace the white-box equivalence oracle with PAC sampling over trees. The resulting algorithm applies unchanged to transformer language models and, more generally, to any acceptor exposing only binary decisions. Second, we further observe that the original framework only ever queries the target on well-formed sequences that can be accepted by the most permissive VPG (called BParse) with the target's ranked alphabet. That is, VPL* is blind to the target's behavior outside BParse. Thus, we propose to sample trees directly instead of sequences and call the target with all the resulting sequences in order to provide an error estimate of how far the target deviates from being a VPG. Last but not least, we develop a learner that captures a tree automaton describing discovered behaviors of the target outside BParse, which results in a larger learnable space. We evaluate the approach on several cases, including transformers trained with Dyck grammars and synthetic targets designed to be outside BParse.
BibTeX
@misc{silva2026learning,
  author = {Juan Pedro da Silva and Sergio Yovine},
  title = {{Learning of Tree Automata applied to Neural Language Acceptors}},
  year = {2026},
  eprint = {2611.10147},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.10147},
}
Figure