Abstract
Extracting finite state automata (FSAs) from black-box models offers a powerful approach to gaining interpretable insights into complex model behaviors. To support this pursuit, we present a weighted variant of Angluin’s (1987) L algorithm for learning FSAs. We stay faithful to the original formulation, devising a way to exactly learn deterministic weighted FSAs whose weights support division. Furthermore, we formulate the learning process in a manner that highlights the connection with FSA minimization, showing how L directly learns a minimal automaton for the target language.
Introduction
In computer science, learning the underlying "rules" of a language from data is a fundamental challenge. Angluin’s L algorithm (1987) provided a landmark solution for boolean regular languages—where a string is either accepted or rejected—by utilizing an active learner* that interacts with an oracle.
However, modern applications, particularly in Natural Language Processing (NLP) and formal verification, often require weighted languages. In these systems, strings are assigned values such as probabilities, execution costs, or weights from a tropical semiring. While weighted versions of L* have been proposed previously, they frequently suffer from two major limitations:
- Algebraic Constraints: Many existing algorithms require weights to belong to a "field," which necessitates the existence of a subtraction operation. Many common weight systems (like the tropical semiring used in shortest-path problems) do not support subtraction.
- Non-determinism: Many algorithms learn non-deterministic automata, which are significantly more difficult to interpret, minimize, and analyze than their deterministic counterparts.
This paper introduces a new weighted version of L designed to exactly learn deterministic weighted finite-state automata (WDFSAs) over semifields*, ensuring the resulting models are both exact and minimal.
Methodology: Learning via Homothetic Equivalence
The proposed Weighted L* algorithm remains faithful to the original active learning framework, relying on two types of queries to an "oracle" (which may be a human expert, a mathematical function, or a complex neural network):
- Membership Queries: The learner asks, "What is the weight of string $x$?"
- Equivalence Queries: The learner asks, "Is my current hypothesis automaton correct?" If not, the oracle provides a counterexample—a string where the hypothesis and the target language disagree.
The Core Innovation
The central challenge in generalizing L to weighted languages is defining when two prefixes should lead to the same state. In the boolean L, two prefixes are equivalent if they behave identically when followed by any possible suffix.
In this weighted version, the authors introduce homothetic equivalence. Two prefixes are considered equivalent if their future weights are "proportional." Specifically, if the weights of all possible completions of two prefixes differ only by a constant scaling factor (a scalar multiple), they are mapped to the same state. This allows the algorithm to handle weights using division (multiplicative inverses) without requiring subtraction.
Maintaining the Hankel Matrix
The algorithm tracks these relationships using an Empirical Hankel Matrix. To ensure the hypothesis is valid, the algorithm employs two critical subroutines:
MAKECONSISTENT: Ensures that if two prefixes are equivalent, appending the same character to both maintains that equivalence.MAKECLOSED: Ensures that every transition from a discovered state leads to a state already represented in the model.
Key Insights and Theoretical Contributions
Faithfulness and Minimality
By generalizing the exact logic of the original L algorithm, the authors prove that their version inherits a crucial property: it learns a minimal* automaton. This means the algorithm naturally discovers the smallest possible machine capable of representing the target language, avoiding the redundancy common in other learning approaches.
The Power of Semifields
By requiring only a semifield (which supports multiplication, addition, and division, but not necessarily subtraction), the algorithm is applicable to a broad range of real-world weight systems. This includes probability distributions ($[0, 1]$) and the tropical semiring ($\mathbb{R} \cup \{\infty\}$), making it highly versatile for NLP and optimization tasks.
Connection to Minimization
The paper illuminates a deep theoretical link between active learning and classical DFA minimization. The process by which L* explores and partitions the state space is shown to be a "discovery" variant of classical algorithms like those proposed by Hopcroft or Mohri.
Results and Complexity
The authors establish several rigorous guarantees for the algorithm:
- Correctness: The algorithm is guaranteed to terminate with a minimal WDFSA that exactly matches the target language, provided the language is determinizable.
- Computational Complexity: The time complexity is established as $O(N^5 M^2 |\Sigma|^2)$, where $N$ is the number of states in the minimal automaton, $M$ is the length of the longest counterexample provided by the oracle, and $|\Sigma|$ is the size of the alphabet.
Limitations and Future Outlook
While the algorithm provides a robust theoretical framework, certain practical challenges remain:
- The Oracle Requirement: Like all L* variants, the algorithm assumes a perfect oracle. In practical scenarios, such as extracting an FSA from a Large Language Model (LLM), providing perfect counterexamples is difficult and often requires heuristic approximations.
- Determinizability: Not all weighted languages can be represented by a deterministic automaton. This algorithm specifically targets the subset of languages that are determinizable; applying it to inherently non-deterministic languages will not yield a perfect representation.
- Model Expressivity: Modern neural architectures like Transformers are more expressive than FSAs. Consequently, extracting an FSA from such models will always involve a degree of simplification or loss of information regarding the model's full behavior.
Summary updated