Dynamic Prompt Learning via Policy Gradient for Semi-structured Mathematical Reasoning

Pan Lu, Liang Qiu, Kai-Wei Chang, Ying Nian Wu, Song-Chun Zhu, Tanmay Rajpurohit, Peter Clark, Ashwin Kalyan

Introduction

Mathematical reasoning is a hallmark of human intelligence, yet it remains a formidable challenge for artificial intelligence. While Large Language Models (LLMs) like GPT-3 have made remarkable strides in solving math word problems presented in plain text, real-world data is rarely so neat. Information is frequently "semi-structured"—embedded in invoices, tax forms, or grade reports.

To bridge this gap, researchers have introduced TabMWP, a massive new dataset of 38,431 math problems requiring reasoning over both text and tables. Alongside this dataset, they developed PromptPG, a reinforcement learning approach that uses policy gradients to dynamically select the best in-context examples for an LLM, outperforming random selection by over 5%.

The Challenge of Tabular Math

Current LLMs struggle with tabular math for two primary reasons:

  1. Heterogeneous Information: Models must successfully align textual questions with specific rows and columns in a table before any mathematical reasoning can begin.
  2. Prompt Instability: In "few-shot" learning, a model is given a few examples to guide its output. However, LLM performance is notoriously sensitive to which examples are chosen. Picking suboptimal examples can cause accuracy to plummet to near-random chance, a problem that is exacerbated by the complexity of multi-step tabular reasoning.

The TabMWP Dataset

To provide a robust benchmark for this challenge, the researchers created TabMWP (Tabular Math Word Problems).

Examples from the TabMWP dataset showing tabular contexts, questions, and step-by-step solutions.

TabMWP stands out due to its scale and complexity:

  • Scale: With 38,431 problems, it is significantly larger than previous tabular math datasets like FinQA or TAT-QA.
  • Complexity: Problems are drawn from grade-level curricula (Grades 1-8) and require multi-step reasoning.
  • Format: Each problem includes a table (provided as an image, semi-structured text, and a structured database), a question, and a "gold" multi-step solution.
  • The "Table-Must" Property: Unlike some datasets where models can guess the answer from the text alone, TabMWP questions are designed so that the table is absolutely indispensable.

PromptPG: Learning to Prompt via Reinforcement Learning

Instead of picking few-shot examples at random or relying on simple keyword matching, the authors propose PromptPG (Prompt Policy Gradient). This system treats prompt selection as a Reinforcement Learning (RL) problem.

The PromptPG Agent architecture, which uses a policy network to sample in-context examples.

The RL framework is structured as follows:

  • The Agent: A policy network built on top of a pre-trained language model (like BERT) with a linear layer.
  • The Action: Selecting a set of $K$ in-context examples from a small candidate pool of training data.
  • The Environment: The GPT-3 API, which receives the prompt and generates a prediction.
  • The Reward: If GPT-3 answers correctly, the agent receives a positive reward; if incorrect, a negative one.

Using the REINFORCE algorithm, the agent learns to identify which examples provide the best "logical scaffolding" for a given test question.

Key Insights and Results

PromptPG reveals that the most helpful in-context example isn't always the one that shares the most vocabulary with the test question. Instead, PromptPG learns to find examples that share underlying reasoning patterns (logical similarity rather than surface similarity).

  • State-of-the-Art Performance: PromptPG achieved an overall accuracy of 68.23%, surpassing the best few-shot Chain-of-Thought (CoT) baseline by 5.31%.
  • Increased Stability: Randomly selecting examples leads to high variance in LLM performance. PromptPG significantly narrows this variance, making outputs much more predictable and reliable.
  • Data Efficiency: The model learns effectively from a very small training pool (only 160 examples), proving that massive compute isn't strictly necessary to optimize prompts.

Limitations and Future Work

Despite these advances, a significant gap remains compared to human performance, which sits at 90.22% on TabMWP. The model still struggles with:

  • Abstract Table Layouts: Non-standard formats, such as "Stem-and-Leaf" plots, require specific domain knowledge to interpret.
  • Long-Chain Arithmetic: When a problem requires a long sequence of calculations (e.g., finding the mean of a large list), the LLM's internal "calculator" is prone to errors.
  • Formatting Sensitivity: The model sometimes calculates the correct answer but fails the evaluation because it outputs a full sentence instead of the requested numerical format.

Future work will likely explore more sophisticated reasoning agents beyond BERT-based selectors and investigate methods to process the visual layouts of tables more directly.

Summary updated

BibTeX
@inproceedings{lu2023dynamic,
  author = {Pan Lu and Liang Qiu and Kai-Wei Chang and Ying Nian Wu and Song-Chun Zhu and Tanmay Rajpurohit and Peter Clark and Ashwin Kalyan},
  title = {{Dynamic Prompt Learning via Policy Gradient for Semi-structured Mathematical Reasoning}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=DHyHRBwJUTN},
}
Figure