Plum: Prompt Learning using Metaheuristic

Rui Pan, Shuo Xing, Shizhe Diao, Xiang Liu, Kashun Shum, Jipeng Zhang, Tong Zhang · OpenReview

Abstract

Since the emergence of large language models, prompt learning has become a popular method for optimizing and customizing these models. Special prompts, such as Chain-of-Thought, have even revealed previously unknown reasoning capabilities within these models. However, the progress of discovering effective prompts has been slow, driving a desire for general prompt optimization methods. Unfortunately, few existing prompt learning methods satisfy the criteria of being truly "general", i.e., automatic, discrete, black-box, gradient-free, and interpretable all at once. In this paper, we introduce metaheuristics, a branch of discrete non-convex optimization methods with over 100 options, as a promising approach to prompt learning. Within our paradigm, we test six typical methods: hill climbing, simulated annealing, genetic algorithms with/without crossover, tabu search, and harmony search, demonstrating their effectiveness in white-box and black-box prompt learning. Furthermore, we show that these methods can be used to discover more human-understandable prompts that were previously unknown in both reasoning and image generation tasks, opening the door to a cornucopia of possibilities in prompt optimization.

1. Introduction

Large Language Models (LLMs) are notoriously sensitive to prompt engineering. The difference between a mediocre and a stellar result often hinges on specific "magic phrases," such as "Let’s think step by step." However, discovering these phrases is typically a slow, manual process of trial and error.

Existing automated methods for prompt optimization often fail to be truly "general." Gradient-based methods require "white-box" access to model weights, which is impossible for closed APIs like GPT-4. Continuous "soft prompt" tuning produces uninterpretable vectors rather than human-readable text. To address these gaps, we introduce Plum (Prompt Learning using Metaheuristic), a framework that treats prompt optimization as a discrete, non-convex optimization problem that is simultaneously automatic, black-box, gradient-free, and interpretable.

2. The Plum Framework

The core idea of Plum is to navigate the space of possible prompts using metaheuristic algorithms originally designed for complex engineering and logistics problems. The framework operates in three primary stages: parsing, neighborhood search, and metaheuristic optimization.

The Plum framework overview, illustrating the evolutionary search loop from discrete prompt parsing to metaheuristic optimization and LLM response evaluation.

2.1 Neighborhood Search and Mutation

To navigate the discrete landscape of natural language, Plum defines the "neighbors" of a prompt through specific edit operations. These operations allow the search algorithms to explore variations of the prompt without requiring gradient information. The primary operations include:

  • Delete: Removing a phrase segment.
  • Swap: Changing the positions of two segments.
  • Add: Inserting a new phrase segment.
  • Paraphrase: Using a model like PEGASUS to reword a segment while preserving its meaning.
Detailed view of mutation operations: delete, swap, paraphrase (using PEGASUS), and add.

2.2 Metaheuristic Optimization

Plum implements six classic algorithms to explore the prompt space:

  • Hill Climbing & Tabu Search: Greedy approaches that move toward better prompts while avoiding recently visited states to prevent cycles.
  • Simulated Annealing: A probabilistic method that occasionally accepts "worse" prompts to escape local optima.
  • Genetic Algorithms (GA): Uses mutation and crossover (combining parts of two successful prompts) to evolve a population.
  • Harmony Search (Plum-HS): Inspired by jazz improvisation, this algorithm generates new prompts by combining segments from a "memory" of past successful prompts and applying fine-tuning adjustments.

3. Experimental Evaluation

We evaluated Plum across several demanding domains, including classification (Natural-Instructions v2.6), reasoning (GSM8K, ASDiv, CSQA), and image generation (Stable Diffusion 2.1). Performance was measured against both open-source models (Phi-2, TinyLlama) and closed-source APIs (GPT-3.5 turbo).

4. Key Results and Insights

  • Superior Accuracy: On black-box reasoning tasks using GPT-3, Plum-HS reached 59.63% accuracy, significantly outperforming the popular GrIPS baseline (54.41%).
  • The Power of Composition: Harmony Search emerged as a standout performer, suggesting that effective prompts are often "composable"—successful instructions from one attempt can be combined with successful examples from another to create a superior "harmony."
  • Interpretability and Discovery: Unlike vector-based tuning, Plum outputs human-readable text. In image generation tasks, Plum improved the average PickScore from 50.0 to 80.6, discovering that phrases like "Is that true? Not at all..." could improve visual quality by adding a sense of mystery.
  • API Efficiency: Plum-TS (Tabu Search) achieved performance comparable to state-of-the-art baselines while using 4x fewer API calls, making it a highly practical choice for budget-constrained development.

5. Conclusion

Plum demonstrates that metaheuristics are a powerful tool for automated prompt engineering. By treating prompts as discrete entities, we can discover effective, interpretable instructions for LLMs without needing internal model access. Future work will explore more complex metaheuristics, such as Particle Swarm or Ant Colony Optimization, and investigate the robustness of these methods against adversarial prompt injection.

Summary updated

BibTeX
@misc{pan2023plum,
  author = {Rui Pan and Shuo Xing and Shizhe Diao and Xiang Liu and Kashun Shum and Jipeng Zhang and Tong Zhang},
  title = {{Plum: Prompt Learning using Metaheuristic}},
  year = {2023},
  eprint = {2311.08364},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.08364},
}
Figure