Efficient Gradient Computation for Structured Output Learning with Rational and Tropical Losses

Corinna Cortes, Vitaly Kuznetsov, Mehryar Mohri, Dmitry Storcheus, Scott YangNeurIPS 2018

This paper addresses a fundamental "disconnect" in machine learning for structured outputs: models are often evaluated using one metric (like edit distance) but trained using another (like cross-entropy) simply because the former is too computationally complex to optimize directly.

Presented at NeurIPS 2018, this work provides a mathematically rigorous and computationally efficient way to calculate exact gradients for "natural" structured loss functions. By leveraging weighted finite-state transducers (WFSTs) and graph algorithms, the authors turn an exponentially difficult optimization problem into one that scales linearly with sequence length.

The Problem: Evaluation vs. Training Mismatch

In structured prediction tasks—such as machine translation, speech recognition, or DNA sequencing—the output is a complex object like a sequence or a tree, rather than a single number or category.

When evaluating these systems, researchers use "natural" losses that measure similarity, such as:

  • Edit-distance: The number of character changes required to match the target.
  • N-gram loss: The number of overlapping snippets of length $n$ that match the target.

However, training a model (like a neural network) requires calculating the gradient of the loss function. For these natural losses, a naïve gradient calculation involves summing over every possible output sequence. Because the number of possible sequences grows exponentially with length, this is computationally intractable for anything beyond very short strings. Consequently, researchers usually settle for "surrogate" losses like cross-entropy, which are easier to differentiate but don't perfectly align with the final evaluation goal.

Methods: Rational and Tropical Losses

The authors bridge this gap by categorizing these complex losses into two broad algebraic families: Rational Losses and Tropical Losses.

1. WFST Representation

They demonstrate that these loss functions can be represented as Weighted Finite-State Transducers (WFSTs). A WFST is essentially a graph where transitions between states have labels and weights, making it ideal for modeling sequence-to-sequence mappings and their associated costs.

Example of a Weighted Finite-State Transducer (WFST) representing sequence operations.

2. Semiring Logic

The framework uses different "semirings" (mathematical systems defining addition and multiplication) to handle different types of losses:

  • Rational losses (like n-gram loss) use the probability semiring.
  • Tropical losses (like edit-distance) use the tropical semiring.

3. The Gradient Algorithm

Instead of summing terms one by one, the authors use standard automata operations—specifically composition, projection, and determinization—to construct a compact graph representing the loss.

The GRAD-RATIONAL algorithm for computing gradients using automata operations.

4. Flow as Gradient

They prove that the gradient can be computed by treating it as a "shortest-distance" or "flow" problem on this graph. This allows them to use efficient dynamic programming (similar to the forward-backward algorithm) to find the exact gradient in polynomial time.

Key Insights and Results

  • Direct Optimization: The primary breakthrough is that approximation is no longer strictly necessary. Complex, non-additive loss functions (like Smith-Waterman alignment) can be placed at the top of a deep neural network, allowing exact backpropagation.
  • Linear Scaling: While the naïve approach scales exponentially (becoming unusable at string lengths greater than 8), the proposed algorithms exhibit linear dependency on the length of the input strings. In runtime tests, the efficient algorithm maintained a low, steady processing time as sequences grew, whereas the naïve version's runtime exploded.
  • Improved Accuracy: The authors tested the learning benefits on an artificial genome sequence dataset. A model trained specifically with the Smith-Waterman loss (a tropical loss) significantly outperformed a baseline model trained with standard cross-entropy, achieving a score of 44.65 versus 42.73.

Limitations and Future Work

While the theoretical and empirical results are strong, the authors note a few limitations:

  • Markovian Constraints: The efficiency of the algorithm depends on the "order" ($q$) of the features used. If features depend on very long-range dependencies within the sequence, the state space of the automata could still become prohibitively large.
  • Scale of Experiments: The experiments serve as a "proof of concept" on sequences of length 50. The next logical step is applying this framework to massive, real-world datasets in machine translation or speech recognition.
  • Approximation for Speed: For extremely large-scale problems, the authors suggest their shortest-path approach could be combined with "pruning" (ignoring low-probability paths) to speed up the process further, though this would transition the method from an exact to an approximate gradient calculation.

Summary updated

BibTeX
@inproceedings{cortes2018efficient,
  author = {Corinna Cortes and Vitaly Kuznetsov and Mehryar Mohri and Dmitry Storcheus and Scott Yang},
  title = {{Efficient Gradient Computation for Structured Output Learning with Rational and Tropical Losses}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
  url = {https://openreview.net/forum?id=rkWvhu-d-B},
}
Figure