Inside-Outside Algorithm for Macro Grammars

Ryuta Kambe, Naoki Kobayashi, Ryosuke Sato, Ayumi Shinohara, Ryo YoshinakaICGI 2021

Abstract

We propose an inside-outside algorithm for stochastic macro grammars. Our approach is based on types, which has been inspired by type-based approaches to reasoning about functional programs and higher-order grammars. By considering type derivations instead of ordinary word derivation sequences, we can naturally extend the standard inside-outside algorithm for stochastic context-free grammars to obtain the algorithm for stochastic macro grammars. We have implemented the algorithm and confirmed its effectiveness through an application to the learning of macro grammars.

Introduction

Formal language theory has long relied on Context-Free Grammars (CFGs) for modeling structured data. However, CFGs are inherently limited; they cannot describe non-semilinear patterns, such as sequences where length doubles at each step. Macro Grammars (MGs) offer a more expressive alternative by allowing non-terminals to take parameters, effectively acting as functions. This capability enables MGs to describe indexed languages, which are vital for sophisticated linguistic modeling and data compression.

Despite their power, learning the parameters of Stochastic Macro Grammars is challenging. The standard Inside-Outside algorithm—a variant of Expectation-Maximization used for CFGs—relies on independent derivation steps that form a tree structure. In MGs, the ability of non-terminals to copy parameters breaks this independence, making traditional derivation trees unsuitable for standard learning algorithms.

Methodology: A Type-Based Approach

The core innovation of this work is treating Macro Grammars as functional programs. Instead of analyzing raw word derivations, the authors utilize intersection types to provide a structured backbone for the learning process.

Type Derivation Trees

In this framework, a type $[i, j]$ represents a term that generates a subword spanning from position $i$ to $j$ in the input string. Because MGs function like programs, the authors can construct "type derivation trees." These trees track how types are assigned to terms, maintaining structure even when parameters are copied or moved.

Inside and outside probabilities defined over type derivation trees for Macro Grammars.

The algorithm defines two key probabilities over these type judgments:

  1. Inside Probability: The probability that a specific type (subword interval) is generated by a non-terminal.
  2. Outside Probability: The probability of generating the remainder of the sentence around that specific type.

To ensure the algorithm remains tractable and terminates, the authors restrict the scope to "expansive grammars," which guarantees finite derivation sequences.

Experimental Evaluation

The algorithm was evaluated on five synthetic languages that pose significant challenges for CFGs:

  • $L_{a^{2^n}}$: A non-semilinear language where string length is a power of 2.
  • $L_{ww}$: The copy language (e.g., "abcabc").
  • $L_{waw}, L_{aww}, L_{www}$: Complex variations of the copy language.

Training was conducted on subsets of these languages with words up to length 9. The algorithm successfully learned correct grammars for all five benchmarks.

Key Results

A notable finding was that the learned grammars often outperformed human-designed "ideal" grammars in terms of likelihood. For instance, in the $L_{a^{2^n}}$ language, the learned grammar achieved a probability of $2.3 \times 10^{-3}$, compared to $1.6 \times 10^{-3}$ for the ideal grammar. This suggests that Stochastic MGs are highly efficient at representing complex data patterns, making them strong candidates for grammar-based data compression.

Conclusion and Future Work

While the proposed algorithm successfully extends the Inside-Outside framework to Macro Grammars, it faces a bottleneck in computational complexity. The "type explosion"—where the number of possible types grows exponentially with input length—limits scalability.

Future research will focus on applying MGs to real-world compression tasks to potentially outperform CFG-based methods like Sequitur. Additionally, the authors aim to refine the type-checking process using "abstraction refinement" to improve speed and extend the framework to even higher-order grammars.

Summary updated

BibTeX
@inproceedings{kambe2021inside,
  author = {Ryuta Kambe and Naoki Kobayashi and Ryosuke Sato and Ayumi Shinohara and Ryo Yoshinaka},
  title = {{Inside-Outside Algorithm for Macro Grammars}},
  booktitle = {ICGI},
  year = {2021},
  url = {https://openreview.net/forum?id=k0kVrpXQev},
}
Figure