Neural Rule-Execution Tracking Machine For Transformer-Based Text Generation

Yufei Wang, Can Xu, Huang Hu, Chongyang Tao, Stephen Wan, Mark Dras, Mark Johnson, Daxin Jiang

Large Language Models (LLMs) like BART and T5 are excellent at generating fluent text, but they are notoriously difficult to control. If you ask a standard Transformer to "generate a 15-word sentence containing 'apple' followed by a sentence containing 'orange'," it will likely fail. This paper introduces the Neural Rule-Execution Tracking Machine (NRETM), a framework designed to bridge the gap between the fluid, "black-box" nature of Transformer-based text generation and the rigid requirements of symbolic logic and hard constraints.

NRETM acts as a plug-and-play module for Transformers that enables them to follow complex, multi-step logical constraints during text generation. By using symbolic "Logic Trackers" to feed a real-time progress report into the model’s decoder, it achieves near-perfect rule adherence without sacrificing text quality or inference speed.

The Challenge of Controllable Generation

Existing solutions for controlling LLM output generally fall into two camps:

  1. Architectural Hacks: Techniques like "Copy Mechanisms" are hard-coded for specific tasks and struggle to scale when multiple, overlapping rules are required.
  2. Constrained Decoding: Methods like "Beam Search" variants prune the model's choices during inference. These are computationally expensive and frequently result in unnatural-sounding text because they force the model into specific tokens regardless of context.

The authors identify a critical need for a unified and scalable way to incorporate fine-grained content control and prior knowledge (such as translation rules) into the generation process.

Methods: Merging Symbolic Computing and Neural Generation

The core innovation of NRETM is the seamless combination of symbolic computing and neural generation. Rules are first expressed as predicate logic formulas using standard operators (AND, OR, NOT)—for example, InSen(apple, 1) ∧ Len(1, 15).

NRETM Architecture showing the Logic Tracker and Control Progress Matrix guiding the Transformer Decoder.

To enforce these rules, the system employs Logic Trackers. These are non-differentiable symbolic programs that monitor the generated output in real-time. For every rule, the tracker returns one of four states:

  • S0: Not a predicate (e.g., a logical operator).
  • S1: Not yet triggered.
  • S2: In progress (often paired with a numerical value, like "5 words remaining").
  • S3: Satisfied.

These states populate a Control Progress Matrix, which aligns the predicates with their current execution status at every decoding step. During neural integration, the Transformer Encoder processes the logical formula as if it were natural language. The Decoder then receives the Control Progress Matrix as a relative position embedding in its cross-attention layer. This acts as a "mentorship" signal, telling the decoder exactly which parts of the rule are finished and which need attention next.

Key Insights

  • The "Progress Bar" for LLMs: Providing the model with a dynamic state of the rules is NRETM's most powerful feature. Instead of forcing the model to "remember" if it used a keyword, the Logic Tracker provides an explicit, continuous signal.
  • Soft Mentorship vs. Hard Masking: Unlike constrained beam search which forces tokens, NRETM guides the model. This allows the model to retain its natural phrasing while still feeling an implicit compulsion to satisfy the rule before generating an End-of-Sequence (EOS) token.
  • Zero-Shot Generalization: Because the model learns to respond to the abstract states of the tracker (S1, S2, S3) rather than specific vocabulary words, it can successfully follow rules it never saw during training.

Datasets and Key Results

The authors evaluated NRETM across three distinct benchmarks: ROCStories (for complex, fine-grained constraints), CommonGen (for generative commonsense reasoning), and TED15 Zh-En (for document-level machine translation).

Performance comparison on ROCStories showing NRETM's massive improvement in Constraint Success Ratio (CSR) over standard T5.

The results demonstrate significant improvements across the board:

  • Superior Controllability: On ROCStories, NRETM achieved a 78.8% Constraint Success Ratio (CSR) on complex tasks where a standard T5 model only managed 15.0%.
  • Better Text Quality: On CommonGen, NRETM achieved ~99% constraint satisfaction. While Grid Beam Search (GBS) can hit 100%, it significantly degrades the CIDEr score (a measure of text quality). NRETM, by contrast, actually improved the CIDEr score over the baseline.
  • Efficiency: NRETM is vastly faster than search-based constraints. In CommonGen tests, NRETM inference took roughly 2.6 minutes compared to 84 minutes for Grid Beam Search.
  • Translation Accuracy: In document-level translation, NRETM reached a 100% Sentence Aligned Ratio, effectively solving the common problem of models skipping sentences in long documents.

Limitations and Future Work

While highly effective, NRETM does have limitations. The framework requires a human to manually write the Python "Logic Tracker" for new types of constraints. Additionally, because the constraint acts as a soft guide rather than a hard lock, there is a minor (<1%) failure rate where the model might generate an EOS token before all rules are met.

Future work may involve pre-training large-scale models directly on massive sets of rules and trackers, paving the way for inherently rule-abiding foundation models.

Summary updated

BibTeX
@inproceedings{wang2021neural,
  author = {Yufei Wang and Can Xu and Huang Hu and Chongyang Tao and Stephen Wan and Mark Dras and Mark Johnson and Daxin Jiang},
  title = {{Neural Rule-Execution Tracking Machine For Transformer-Based Text Generation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=9AN7CLOYNeW},
}
Figure