Enhancing Input-Label Mapping in In-Context Learning with Contrastive Decoding

Keqin Peng, Liang Ding, Yuanxin Ouyang, Meng Fang, Yancheng Yuan, Dacheng Tao

Abstract

Large Language Models (LLMs) demonstrate remarkable In-Context Learning (ICL) capabilities, yet they often struggle to prioritize the specific input-label mappings provided in a prompt over their internal pre-training biases. This paper introduces In-Context Contrastive Decoding (ICCD), a training-free inference-time method designed to strengthen the model's adherence to provided examples. By contrasting the output distributions of a standard few-shot prompt with a corrupted version, ICCD effectively isolates and amplifies the task-specific knowledge contained within the context. Our evaluations across multiple Natural Language Understanding (NLU) benchmarks and model families demonstrate consistent performance improvements, particularly in larger-scale models.

Introduction

In-Context Learning (ICL) has become the primary paradigm for deploying Large Language Models on novel tasks without the need for parameter updates. However, the mechanism by which LLMs learn from context is often bifurcated into two distinct processes: Task Recognition and Task Learning. While LLMs are adept at recognizing the general task (e.g., identifying that a prompt requires sentiment analysis), they frequently fail at Task Learning—the ability to map specific inputs to specific labels based on the provided examples.

Research indicates that LLMs are often "lazy" learners, defaulting to pre-existing biases acquired during pre-training rather than strictly following the input-label mappings in the prompt. This leads to a failure in scenarios where the prompt contains counter-intuitive examples or specific mapping logic that contradicts the model's "gut feeling." To address this, we propose In-Context Contrastive Decoding (ICCD), a method that forces the model to attend more closely to the provided context by contrasting correct and incorrect mappings.

Methodology: In-Context Contrastive Decoding (ICCD)

ICCD is a training-free, plug-and-play method that modifies the decoding process. The core intuition is inspired by traditional contrastive decoding: to amplify the "correct" signal by subtracting a "distractor" or "negative" signal.

Context Construction

The method utilizes two distinct prompts during inference:

  1. Positive Context ($c$): A standard few-shot prompt containing correct input-label pairs.
  2. Negative Context ($c^-$): A corrupted version of the prompt. Through empirical testing, it was determined that the most effective corruption strategy involves keeping the labels fixed while swapping the inputs with random samples from different categories. This specifically disrupts the input-label mapping while maintaining the task structure.

The Contrastive Step

During the generation of each token, the model calculates the logit distributions for both the positive and negative contexts. The final output distribution is adjusted to boost tokens that are highly probable in the positive context but less probable in the negative context. The mathematical formulation is as follows:

$$y_t \sim \text{softmax}(\mathbf{z}_t + \alpha(\mathbf{z}_t - \mathbf{z}_t^-))$$

Where:

  • $\mathbf{z}_t$ represents the logits from the correct prompt.
  • $\mathbf{z}_t^-$ represents the logits from the corrupted prompt.
  • $\alpha$ is a hyperparameter that controls the strength of the contrastive influence.

By subtracting the negative distribution, ICCD effectively "factors out" the model's internal priors and isolates the specific information gained from the input-label mappings provided in the context.

Experimental Setup

Datasets

We evaluated ICCD across seven diverse NLU tasks to ensure robustness:

  • Sentiment Analysis: SST-2, SST-5, and CR.
  • Subjectivity Analysis: Subj.
  • Topic Classification: AG_NEWS.
  • Natural Language Inference (NLI): MNLI and QNLI.
  • Multi-class Scaling: TREC (6 classes) and Dbpedia (14 classes) were used to test the method’s scalability beyond binary classification.

Models

The experiments utilized modern open-source model families, including Llama-3.1, Llama-3.2, and Qwen2, with parameter counts ranging from 0.5B to 8B. Both base and instruction-tuned (Chat/Instruct) versions were tested.

Key Results and Insights

Consistent Performance Gains

ICCD demonstrated consistent improvements across nearly all tasks and models. On average, the method provided a performance boost of up to +1.8 points. The benefits were particularly notable in larger models; for instance, the Qwen2-1.5B model saw an average gain of +2.3 points. In complex NLI tasks, Llama-3.1-8B achieved improvements of 5.1% on QNLI and 1.8% on MNLI.

Input vs. Label Corruption

A significant finding of this research is that scrambling the inputs while keeping labels fixed is more effective than scrambling the labels. This suggests that altering labels may introduce unpredictable new biases, whereas input corruption more cleanly isolates the mapping logic the model is intended to learn from the context.

Complementarity and Sensitivity

ICCD is agnostic to the example selection strategy. Whether examples are chosen randomly, via BM25 similarity, or through TopK embeddings, ICCD consistently enhances performance. Furthermore, KL divergence analysis confirmed that the output distributions for positive and negative contexts are significantly distinct, proving that the model is indeed sensitive to the mapping corruption and that ICCD successfully leverages this sensitivity.

Limitations and Future Work

While effective, ICCD introduces certain trade-offs:

  • Computational Overhead: The requirement for two forward passes (positive and negative) increases inference time and compute resource consumption, though these passes can be parallelized.
  • Model Scaling: The study focused on models up to 8B parameters. Future research is required to determine if ultra-large models (70B+)—which may already possess stronger ICL capabilities—benefit similarly.
  • Task Generalization: This work focused on classification and NLU. Future iterations should explore the applicability of ICCD to generative tasks such as summarization, translation, or creative writing.

Conclusion

In-Context Contrastive Decoding provides a simple yet powerful mechanism to improve the reliability of LLMs in few-shot scenarios. By explicitly contrasting correct and incorrect input-label mappings, ICCD mitigates pre-training bias and ensures that models truly "learn" from the provided context rather than merely recognizing the task at hand.

Summary updated

BibTeX
@inproceedings{peng2025enhancing,
  author = {Keqin Peng and Liang Ding and Yuanxin Ouyang and Meng Fang and Yancheng Yuan and Dacheng Tao},
  title = {{Enhancing Input-Label Mapping in In-Context Learning with Contrastive Decoding}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.acl-short.77},
}
Figure