Abstract
As Large Language Models (LLMs) become a staple for text annotation in the social sciences, the sensitivity of these models to specific prompt wording remains a critical concern. This paper investigates the impact of prompt selection on classification accuracy, finding variations of up to 18% in F1-scores based on phrasing alone. We propose a systematic framework for Automatic Prompt Optimization (APO) and introduce Prompt Ultra, a browser-based, no-code tool designed to democratize advanced prompt engineering for researchers.
Introduction
Social scientists increasingly leverage LLMs to label large-scale text datasets for variables such as sentiment, political orientation, and toxicity. While this transition offers efficiency, it often relies on "intuitive" or hand-crafted prompts. This study addresses the lack of systematic prompt selection in social science research, which can lead to sub-optimal accuracy and hidden biases. We demonstrate that the specific wording of instructions is not a minor detail but a primary determinant of model performance.
Methods and Optimization Strategies
The study evaluates two primary methodologies for prompt development across seven diverse classification tasks:
- Hand-crafted Heuristics: Five common prompt engineering techniques were tested:
- Simple: Minimalist, direct instructions.
- Explanations: Providing sociological context or explicit definitions.
- Examples: Few-shot prompting using four labeled instances.
- Roleplay: Instructing the model to adopt a specific persona (e.g., "political analyst").
- Chain of Thought (CoT): Requiring the model to output its reasoning step-by-step before providing a label.
- Automatic Prompt Optimization (APO): This iterative approach uses an LLM to rephrase a seed prompt. Variations are evaluated against a small "gold standard" validation set (e.g., 400 samples). The best-performing prompts are selected to seed the next generation of variations, refining the instruction set over several cycles.
The Prompt Ultra Tool
To bridge the technical gap for non-computational researchers, the authors developed Prompt Ultra. This web-based application facilitates the APO process and dataset labeling via API without requiring programming knowledge.
Experimental Setup
The performance of these strategies was benchmarked across seven social science tasks:
- TweetEval: Subsets for Hate Detection, Emotion Recognition, Sentiment Analysis, and Offensive Language.
- TML-sent: Multilingual tweet sentiment analysis across eight languages.
- AS-pol: Classification of political bias in US news articles.
- LibCon: Identification of political leaning in Reddit posts.
Key Findings
The Impact of Prompt Variance
The most significant finding is the "18% swing": the difference in F1-score between the most and least effective prompts for a single task reached 18 percentage points. This suggests that research findings based on a single, unoptimized prompt may be highly unstable.
No Universal Heuristic
Contrary to common belief, popular techniques like "Chain of Thought" or "Roleplay" are not universally superior. A heuristic that excelled on one dataset often underperformed on another, highlighting the task-specific nature of prompt effectiveness.
Data Contamination Concerns
The study identified a "cheating" phenomenon where GPT-3.5 performed significantly better on the training sets of established benchmarks than on their respective test sets. This indicates that these public datasets were likely included in the model's pre-training data, necessitating caution when using older benchmarks for validation.
The Reliability of APO
While APO did not always produce the absolute best prompt, it consistently ranked among the top performers. It offers a "safe bet" for researchers, providing high-quality results without the trial-and-error associated with manual prompt engineering.
Results
APO outperformed all hand-crafted heuristics in four out of seven tasks and remained competitive in the others. For instance, in the TE-emotion task, APO achieved a peak F1-score of 79.9%. The study also demonstrated that effective prompts can be evolved within approximately 15 generations using only a few hundred labeled examples, making the process computationally and financially efficient for large-scale applications.
Discussion and Conclusion
The sensitivity of LLMs to prompt phrasing introduces a new layer of researcher degrees of freedom in automated content analysis. Systematic optimization via APO provides a robust path forward, mitigating the risks of arbitrary prompt selection.
Future work should address the limitations of current LLMs, including the "black box" nature of proprietary models and the need for constant re-optimization as models are updated. Furthermore, exploring the use of LLM-generated justifications and confidence scores could further enhance the reliability of automated social science research.
Summary updated