Abstract
GRL-Prompt is a novel framework that optimizes Large Language Model (LLM) prompts by framing the task as a reinforcement learning (RL) problem over Knowledge Graphs (KGs). By modeling the structural relationships between user queries and candidate examples, GRL-Prompt learns to select and, crucially, order examples to maximize in-context learning performance. Evaluated on Alpaca and Dolly datasets across GPT-4, GPT-3, and LLaMA, the framework demonstrates significant improvements in ROUGE and BLEU scores while achieving faster convergence compared to existing baselines.
Introduction
Large Language Models (LLMs) exhibit extreme sensitivity to prompt composition, particularly in In-Context Learning (ICL) scenarios. Small changes in example selection or ordering—a phenomenon known as permutation sensitivity—can lead to drastic performance variations. Traditional methods like manual crafting are labor-intensive, while random selection or k-NN retrieval often fail to explore the prompt space effectively or ignore the importance of sequence. GRL-Prompt addresses these challenges by using a graph-based policy network to optimize both selection and ordering in a model-agnostic, "plug-and-play" fashion.
Methodology
The GRL-Prompt architecture comprises three main pillars designed to capture and exploit the relationships between queries and examples.
Knowledge Graph (KG) Construction and Learning
Instead of treating examples as isolated text chunks, the framework builds a heterogeneous graph where nodes represent the user query and candidate examples. A Heterogeneous Graph Transformer (HGT) encodes these nodes into embeddings that capture deep structural correlations between the user's intent and the available data.
Policy Network
The policy network consists of two specialized components:
- In-context Matching Network (ICMN): Calculates the probability of selecting a specific example based on its relevance to the query.
- Pairwise Edge Classifier (PEC): Predicts the relative order between any two examples. The final prompt sequence is then determined via a Topological Sort of these pairwise preferences.
Embedding-based Reward Shaping
To stabilize RL training against "black-box" LLM outputs, the authors designed a reward function combining textual similarity (ROUGE/BLEU) with cosine embedding similarity. This provides a smoother gradient for the agent, allowing for faster and more reliable convergence.
Experiments and Results
The researchers evaluated GRL-Prompt on two major instruction-following datasets: Alpaca (52,000 pairs) and Dolly (15,000 records). Testing spanned three distinct LLMs—GPT-4, GPT-3, and LLaMA—to demonstrate the framework's versatility.
Performance Gains
GRL-Prompt consistently outperformed state-of-the-art baselines such as PromptPG and UDR. It achieved average increases of 0.10 in ROUGE-1, 0.07 in ROUGE-2, and 0.05 in BLEU scores. Ablation studies confirmed that removing the Knowledge Graph component led to a performance drop of up to 0.06 in ROUGE-1, highlighting the importance of structured context.
Training Efficiency
Beyond raw performance, GRL-Prompt exhibits superior training efficiency. The framework converges significantly faster than the UDR baseline, reaching lower loss levels in fewer epochs across both the Alpaca and Dolly datasets.
Conclusion and Future Work
GRL-Prompt demonstrates that the ordering of examples is as vital as their content for effective in-context learning. By leveraging KGs and RL with shaped rewards, it provides a robust solution for prompt optimization. Future research will focus on integrating human feedback into the reward loop to capture nuances beyond automatic metrics and exploring ways to reduce the computational overhead of graph construction.
Summary updated