Introduction
Large Language Models (LLMs) have demonstrated remarkable capabilities across diverse tasks, yet they remain notoriously sensitive to the specific phrasing of instructions. While automatic prompt engineering tools like Automatic Prompt Engineer (APE) have been developed to find "optimal" prompts using labeled data, these solutions often suffer from a significant "generalization gap." A prompt optimized for a specific dataset (the source) frequently performs poorly when applied to a different dataset (the target) due to distribution shifts—variations in linguistic style, topic, or label frequency.
In real-world applications, developers often possess labeled data for one domain but need the model to function effectively on a new, unlabeled domain. Manually re-optimizing prompts for every new user group is both expensive and inefficient. This paper introduces Generalized Prompt Optimization (GPO), a framework designed to create a single, robust prompt that generalizes to unlabeled target groups without sacrificing performance on the original source data.
The GPO Framework
To address the lack of labels in the target distribution, GPO leverages the LLM's own reasoning and instruction-following capabilities to bridge the gap. The framework operates through a three-step gradient-free process, making it suitable for black-box models like GPT-4.
1. Prompt Generation via Meta-Prompting
Using the labeled source data, the system employs a meta-prompt to ask an LLM to generate $K$ different candidate prompts that accurately describe the underlying task. This step ensures a diverse set of potential instructions.
2. Prompt Ensemble Labeling
These $K$ candidate prompts are then used to label the unlabeled target data. To ensure high-quality "pseudo-labels," GPO utilizes an ensemble strategy: a label is only accepted if a specific percentage (the consistency threshold $T$) of the candidate prompts agree. This filtering mechanism effectively removes noisy labels that could otherwise degrade the optimization process.
3. Joint Prompt Optimization
The labeled source data and the newly pseudo-labeled target data are combined. The target data is upsampled to match the source size, and a standard gradient-free optimizer is applied to this unified dataset to derive the final robust prompt.
Experimental Evaluation
The researchers evaluated GPO across 16 datasets covering six diverse NLP tasks, including Sentiment Analysis (Yelp, Flipkart, IMDB, Amazon), Commonsense QA (SocialIQA, PIQA, OpenbookQA), and Multi-turn Dialog (DSTC7, Ubuntu Dialog, MuTual).
Key Results
GPO consistently outperformed standard optimization methods on target distributions while maintaining competitive results on source distributions. For instance, in sentiment analysis tasks, GPO demonstrated superior cross-domain robustness.
As shown in the results table, when moving from a Yelp source to a Flipkart target, standard APE performance often drops significantly (to approximately 78.4%). GPO, by incorporating target distribution information, achieves higher accuracy (reaching 84.5% on Flipkart) and maintains stability across different review platforms. Similar improvements were noted in complex reasoning tasks like DROP, where GPO nearly doubled the performance of baselines on text span identification.
Insights and Discussion
Several key findings emerged from the study:
- The Robustness Gap: Prompts optimized on a single dataset can see performance drops of over 8% when applied to similar tasks in different domains.
- Diversity and Generalization: Source groups with high n-gram diversity tend to produce more resilient prompts. Diversity in the training data naturally encourages the optimizer to find more generalizable instructions.
- Ensembles as Noise Filters: The ensemble labeling approach is critical. By requiring high consistency, GPO prevents hallucinations from "poisoning" the final prompt optimization.
Conclusion and Future Work
GPO provides a robust, model-agnostic framework for optimizing prompts against distribution shifts. While effective, the method currently requires access to unlabeled target inputs and focuses primarily on instruction text rather than in-context learning (ICL) examples. Future research will explore optimizing the selection of few-shot examples to further enhance robustness and investigate the framework's performance on smaller, weaker models that may struggle with self-labeling.
Summary updated