Context-aware Prompt Tuning: Advancing In-Context Learning with Adversarial Methods

Tsachi Blau, Moshe Kimhi, Yonatan Belinkov, Alexander M. Bronstein, Chaim Baskin · DOI

Context-aware Prompt Tuning (CPT) is a novel approach to few-shot learning that bridges the gap between the efficiency of In-Context Learning (ICL) and the optimization power of Prompt Tuning (PT). By treating the refinement of input examples as a constrained optimization problem—inspired by adversarial attack methodologies—CPT extracts deeper insights from training data without the typical overfitting associated with fine-tuning.

Introduction

Few-shot learning in Large Language Models (LLMs) generally faces a trade-off between stability and performance. In-Context Learning (ICL) provides examples in the prompt without changing weights, making it stable but often limited in task comprehension. Conversely, optimization-based methods like Fine-tuning, LoRA, or Prompt Tuning update parameters to improve performance but are notoriously prone to overfitting in low-data scenarios.

The authors identify a significant "train-test loss gap" where methods like Prompt Tuning achieve near-zero training loss but fail to generalize to new data. CPT aims to provide the best of both worlds: the optimization-driven performance of PT with the generalization stability of ICL.

Methodology

CPT introduces several novel technical components to optimize learning from a few examples:

  • Context Embedding Refinement: Unlike standard Prompt Tuning, which adds new "learnable" tokens, CPT optimizes the embeddings of the actual training examples provided in the context.
  • Adversarial-Inspired Optimization: The method utilizes Projected Gradient Descent (PGD). It treats the input as something to be "attacked" to minimize loss, applying an $\ell_2$ norm constraint to ensure the optimized embeddings stay close to their original values, thus preserving semantic meaning.
  • Label-Aware Loss & Recency Bias: CPT calculates a weighted loss across all labels in the context and applies exponentially decaying weights to prioritize examples closer to the final query, leveraging the LLM's natural recency bias.
  • Selective Updates: The embeddings of input text and templates are updated, while ground-truth label tokens remain frozen to serve as task anchors.

Experimental Setup

The authors evaluated CPT on several standard NLP classification benchmarks: SST-2 (sentiment), AG News (news category), DBpedia (14-class ontology), and TREC (question type). Additionally, a synthetic Set Classification benchmark was introduced to test the model's ability to learn arbitrary categories without relying on pre-existing knowledge.

Analysis of Generalization and Overfitting

A key insight of CPT is its use of "friendly" adversarial attacks to regularize learning. By constraining updates via PGD, the model is prevented from finding "shortcuts" that lead to overfitting.

Figure 1: Comparison of training and test cross-entropy loss across different methods. CPT maintains a significantly smaller gap between training and test loss compared to methods like IPT, indicating superior generalization.

As shown in Figure 1, while CPT may have a higher training loss than Prompt Tuning, it achieves a much lower test loss. This confirms that the constraints imposed by CPT act as a powerful regularizer, effectively mitigating the overfitting common in few-shot optimization.

Key Results

CPT consistently outperformed ICL, PT, IPT, and LoRA across almost all tested scenarios. The performance gains were particularly pronounced as the underlying model strength increased (e.g., Llama3 8B) and on more complex tasks with numerous classes.

Figure 6: Test set accuracy across four benchmark datasets. CPT (red) consistently achieves higher accuracy and lower variance compared to baselines like ICL, PT, and LoRA.

On the 14-class DBpedia dataset with 6 shots using Llama3, CPT achieved 82.42% accuracy, significantly outperforming ICL (~80%) and LoRA (~63%). Furthermore, CPT demonstrated greater reliability, showing lower standard deviation across different templates and random seeds compared to traditional baselines.

Conclusion

While CPT offers superior accuracy and robustness, it comes with increased computational costs due to the iterative optimization required for each new context. It is also subject to the same context window limitations as ICL. Future work will focus on improving optimization efficiency and scaling the method to longer context windows. CPT represents a significant step forward in making few-shot learning both powerful and generalizable.

Summary updated

BibTeX
@misc{blau2024context,
  author = {Tsachi Blau and Moshe Kimhi and Yonatan Belinkov and Alexander M. Bronstein and Chaim Baskin},
  title = {{Context-aware Prompt Tuning: Advancing In-Context Learning with Adversarial Methods}},
  year = {2024},
  eprint = {2410.17222},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.17222},
}
Figure