Tensors over Semirings for Latent-Variable Weighted Logic Programs

Esma Balkir, Daniel Gildea, Shay B. Cohen

Abstract

Semiring parsing is an elegant framework for describing parsers by using semiring weighted logic programs. In this paper, we present a generalization of this concept: latent-variable semiring parsing. With our framework, any semiring weighted logic program can be latentified by transforming weights from scalar values of a semiring to rank-n arrays, or tensors, of semiring values, allowing the modelling of latent variables within the semiring parsing framework. Semiring is too strong a notion when dealing with tensors, and we have to resort to a weaker structure: a partial semiring. We prove that this generalization preserves all the desired properties of the original semiring framework while strictly increasing its expressiveness.

Introduction: The Power of Semiring Parsing

In natural language processing, "parsing as deduction" is a classic framework where parsing algorithms, such as the CKY algorithm, are written declaratively as logic programs. In 1999, Joshua Goodman introduced semiring parsing, demonstrating that if the weights of a grammar belong to a mathematical structure called a semiring, the same logic program can be used to compute various results—such as the boolean recognizer, the total probability of a string, or the single best parse tree—simply by swapping the semiring.

Figure 1: A standard semiring derivation tree where each rule application is associated with a weight from a semiring.

The Challenge: Latent Variables and Tensor Weights

Modern NLP relies heavily on latent-variable models (e.g., Latent-Variable PCFGs), which assume hidden states explain the observed data. In these models, grammar rules are not weighted by single numbers (scalars), but by vectors, matrices, or higher-order tensors.

However, a collection of arbitrary tensors does not form a strict mathematical semiring because addition and multiplication are only defined for compatible dimensions. Consequently, the highly useful semiring parsing framework could not natively support latent-variable models. This paper bridges that gap by introducing a generalized framework that accommodates these multi-dimensional structures.

Methods: Partial Semirings and Tensors

The authors generalize Weighted Logic Programs (WLPs) to use tensors over semirings. This involves several key mathematical innovations:

  • Partial Semirings: They define a weaker algebraic structure called a partial semiring. In this structure, addition (element-wise) and multiplication (tensor contraction) are only defined when the dimensions of the tensors match.
  • Dimension Matching as a Type System: To ensure mathematical consistency, the authors establish a rule for Context-Free Grammars (CFGs): every non-terminal is assigned a specific vector space dimension. This ensures that tensor operations for any valid grammar rule always have matching dimensions, acting as a type-checking system for the dynamic programming chart.
  • Generalized Inside/Outside Algorithms: The authors extend Goodman's classic algorithms to handle tensor weights. Because tensor contraction is non-commutative, they introduce a novel formulation for the Outside algorithm using permutation operators to track and shift tensor indices correctly.
Figure 2: A latent-variable derivation tree illustrating how weights are transformed into tensors within specific product spaces defined by the non-terminals.

Key Insights: Distributivity and Non-Commutativity

The core requirement for efficient dynamic programming is the distributive property ($a \times b + a \times c = a \times (b+c)$). The authors prove that tensor contraction distributes over element-wise tensor addition, which is why their partial semiring framework successfully supports dynamic programming despite the weaker algebraic constraints.

Furthermore, they elegantly address the non-commutative nature of tensor multiplication. Unlike scalar probabilities where $a \times b = b \times a$, tensor order matters. The authors solve this in the Outside algorithm by formally defining how to "rotate" or permute the dimensions of the tensors so that the correct ranks are contracted without breaking the sequence.

Theoretical Results

As a foundational theoretical paper, the main results are rigorous mathematical proofs rather than empirical benchmarks:

  • Correctness: The authors prove that item-based parser descriptions remain correct under the partial semiring framework.
  • Exact Formulas: They derive generalized formulas for computing Inside and Outside values for tensor-weighted logic programs.
  • Looping Buckets: They successfully extend their proofs to handle cyclic dependencies (e.g., $A \to B$ and $B \to A$) by using the supremum of partial sums, proving that tensors of semirings remain $\omega$-continuous.

Conclusion and Future Work

While the proofs in this paper focus on Context-Free Grammars, the principles are designed to be broadly applicable. This framework allows latent variables to be seamlessly incorporated into declarative WLP toolkits like Dyna. This could drastically streamline the creation of Expectation-Maximization (EM) or spectral learning algorithms for complex formalisms, including Tree-Adjoining Grammars (TAG), Combinatory Categorial Grammars (CCG), and Machine Translation systems.

Summary updated

Abstract

Semiring parsing is an elegant framework for describing parsers by using semiring weighted logic programs. In this paper we present a generalization of this concept: latent-variable semiring parsing. With our framework, any semiring weighted logic program can be latentified by transforming weights from scalar values of a semiring to rank-n arrays, or tensors, of semiring values, allowing the modelling of latent variables within the semiring parsing framework. Semiring is too strong a notion when dealing with tensors, and we have to resort to a weaker structure: a partial semiring. We prove that this generalization preserves all the desired properties of the original semiring framework while strictly increasing its expressiveness.
BibTeX
@inproceedings{balkir2020tensors,
  author = {Esma Balkir and Daniel Gildea and Shay B. Cohen},
  title = {{Tensors over Semirings for Latent-Variable Weighted Logic Programs}},
  booktitle = {IWPT},
  year = {2020},
  doi = {10.18653/v1/2020.iwpt-1.8},
}
Figure