Introduction
The performance of pre-trained language models (PLMs) in knowledge retrieval tasks is highly sensitive to the prompts used to query them. Traditionally, prompts are either manually crafted or searched for as "universal" templates applied across all instances of a specific task. However, a static prompt like [sub] was born in [MASK]. may not be optimal for all subjects; a modern figure might benefit from different contextual cues than a historical one.
To address this, we present PromptGen, a framework that generates dynamic, instance-level prompts. By tailoring the context to specific subjects, PromptGen significantly enhances the ability of Masked Language Models (MLMs) to retrieve factual information from their latent parameters.
Methodology
PromptGen treats prompt engineering as a sequence-to-sequence generation task using a BART-large architecture.
Architecture
The system consists of a generative encoder-decoder and a frozen downstream MLM.
- Encoder: Receives the subject and relation (e.g.,
<Obama, place of birth>). - Autoregressive Decoder: Generates "trigger" tokens that surround the subject and mask.
- Masked Language Model: Receives the generated prompt and predicts the target object.
Training and Constraints
The model is trained end-to-end to minimize the cross-entropy loss of the MLM's predictions. To ensure differentiability, BART's output tokens are represented as soft distributions over the vocabulary.
A critical challenge in using a powerful generator like BART is "label leaking"—where the generator might already know the answer and include it in the prompt. To prevent this, we introduce a None Perturbation strategy. By replacing the subject with a "None" token and penalizing the model if it still predicts the correct answer, we ensure the generated text functions as a template rather than a direct answer key.
Experimental Results
We evaluated PromptGen on the LAMA benchmark, covering 41 relations from T-REx and Wikidata.
Performance Comparison
PromptGen achieves state-of-the-art results, reaching 51.0% top-1 accuracy, a significant improvement over manual prompts (31.1%) and previous automated methods like OptiPrompt (48.6%).
The results indicate that dynamic prompts are particularly effective for N-1 and N-M relations, where subject-specific context helps resolve ambiguities that static prompts cannot. However, for 1-1 relations (e.g., "capital of"), manual prompts remain competitive due to the inherent lack of linguistic variety in those facts.
Discussion and Conclusion
The success of PromptGen highlights the importance of dynamic context in prompt learning. By acting as an "interpreter" for frozen MLMs, the generative model learns to navigate the latent space of the target model more effectively. While the approach introduces some computational overhead during inference, its ability to bypass majority biases and adapt to specific inputs represents a significant step forward in automated prompt engineering. Future work will explore extending this framework to tasks beyond factual probing, such as sentiment analysis and natural language inference.
Summary updated