Customizing Language Model Responses with Contrastive In-Context Learning

Xiang Gao,Kamalika Das
2024-04-08
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
Computation and Language,Artificial Intelligence
What problem does this paper attempt to address?
### Problems the Paper Aims to Solve This paper aims to address the issue of large language models (LLMs) struggling to align with user intent when generating content. Specifically, when there is a need to generate content in a specific style or tone, existing LLMs often fail to meet user requirements. To tackle this challenge, the authors propose a method based on contrastive examples (Contrastive In-Context Learning), which uses positive and negative examples to better describe user intent. ### Main Contributions 1. **Proposed a new method**: Utilizing contrastive examples (including both positive and negative examples) to improve the quality of content generated by LLMs. 2. **Experimental validation**: Conducted experiments on synthetic datasets and real-world datasets (such as StackExchange and Reddit), showing that this method significantly improves performance. 3. **Demonstrated the potential of negative examples**: Negative examples can more effectively guide LLMs to generate content that aligns with user preferences. ### Method Overview 1. **Obtaining contrastive examples**: - **Using annotated feedback**: Extract high-scoring and low-scoring responses from user feedback as positive and negative examples. - **Automatically generating negative examples**: If annotated feedback is unavailable, LLM can generate responses to be used as negative examples. - **Automated evaluation**: For certain tasks, automatic evaluation rules can be defined to select positive and negative examples. 2. **Forming prompts**: - **Contrastive examples as few-shot examples**: Provide contrastive example pairs as few-shot examples to the LLM. - **Inference and analysis**: Require the LLM to analyze the characteristics of positive and negative examples, then generate a response that aligns with user preferences. ### Experimental Setup - **Datasets**: Including StackExchange, Reddit, and synthetic datasets. - **Models**: Used non-dialogue LLMs (such as GPT-3) and dialogue LLMs (such as ChatGPT and GPT-4). - **Evaluation methods**: Including reference-based evaluations (such as BERT Score and sentence embedding similarity) and reference-free evaluations (such as DialogRPT and GPT Score). ### Experimental Results - **Contrastive-Combined method**: Combining contrastive examples with instructions performed best in most cases. - **Source of negative examples**: Both human-written and LLM-generated negative examples effectively improved performance. - **Reducing prompt length**: Compressing contrastive examples into brief instructions can reduce prompt length and cost. ### Conclusion By introducing contrastive examples, especially negative examples, the quality of content generated by LLMs can be significantly improved to better align with user preferences. This method not only performs well on synthetic datasets but also achieves significant improvements on real-world datasets.