Customizing Language Model Responses with Contrastive In-Context Learning
Xiang Gao, Kamalika Das
Abstract
Large language models (LLMs) are becoming increasingly important for machine learning applications. However, it can be challenging to align LLMs with our intent, particularly when we want to generate content that is preferable over others or when we want the LLM to respond in a certain style or tone that is hard to describe. To address this challenge, we propose an approach that uses contrastive examples to better describe our intent. This involves providing positive examples that illustrate the true intent, along with negative examples that show what characteristics we want LLMs to avoid. The negative examples can be retrieved from labeled data, written by a human, or generated by the LLM itself. Before generating an answer, we ask the model to analyze the examples to teach itself what to avoid. This reasoning step provides the model with the appropriate articulation of the user's need and guides it towards generting a better answer. We tested our approach on both synthesized and real-world datasets, including StackExchange and Reddit, and found that it significantly improves performance compared to standard few-shot prompting.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Cited by top-tier papers9
- Learning from Mistakes: Negative Reasoning Samples Enhance Out-of-Domain GeneralizationTian Xueyun, Minghua Ma, Bingbing Xu, Nuoyan Lyu et al.ACL 2026 · 3 citations
- RIMRULE: Improving Tool-Using Language Agents via MDL-Guided Rule LearningXiang Gao, Yuguang Yao, Qi Zhang, Kaiwen Dong et al.ACL 2026 · 2 citations
- Q-Adapter: Customizing Pre-trained LLMs to New Preferences with Forgetting MitigationYi-Chen Li, Fuxiang Zhang, Wenjie Qiu, Lei Yuan et al.ICLR 2025 · 1 citation
- Network-Level Prompt and Trait Leakage in Local Research AgentsHyejun Jeong, Mohammadreza Teymoorianfard, Abhinav Kumar, Amir Houmansadr et al.USENIX Security 2026 · 1 citation
- PANDAS: Improving Many-shot Jailbreaking via Positive Affirmation, Negative Demonstration, and Adaptive SamplingAvery Ma, Yangchen Pan, Amir-massoud FarahmandICML 2025
Builds on9
- Learning Transferable Visual Models From Natural Language SupervisionAlec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh et al.ICML 2021 · 47,906 citations
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
- BERTScore: Evaluating Text Generation with BERTTianyi Zhang, Varsha Kishore, Felix Wu, Kilian Q. Weinberger et al.ICLR 2020 · 8,443 citations
- Flamingo: a Visual Language Model for Few-Shot LearningJean-Baptiste Alayrac, Jeff Donahue, Pauline Luc, Antoine Miech et al.NeurIPS 2022 · 6,707 citations
- Large Language Models are Human-Level Prompt EngineersYongchao Zhou, Andrei Ioan Muresanu, Ziwen Han, Keiran Paster et al.ICLR 2023 · 297 citations
Related papers
- Co-Evolving LLMs and Embedding Models via Density-Guided Preference Optimization for Text ClusteringZetong Li, Qinliang Su, Minhua Huang, Yin YangEMNLP 2025
- Generating Diverse Training Samples for Relation Extraction with Large Language ModelsZexuan Li, Hongliang Dai, Piji LiACL 2025
- AvaTaR: Optimizing LLM Agents for Tool Usage via Contrastive ReasoningShirley Wu, Shiyu Zhao, Qian Huang, Kexin Huang et al.NeurIPS 2024 · 95 citations
- Interpreting Language Reward Models via Contrastive ExplanationsJunqi Jiang, Tom Bewley, Saumitra Mishra, Freddy Lécué et al.ICLR 2025
- What Matters in Data for DPO?Yu Pan, Zhongze Cai, Huaiyang Zhong, Guanting Chen et al.NeurIPS 2025 · 13 citations
