Learning to Retrieve In-Context Examples for Large Language Models

Liang Wang, Nan Yang, Furu Wei
7/14/2023
cs.CLcs.IR

Official code: microsoft/LMOps (4,440 stars, MIT, last commit 2026-04-30).

Abstract

Large language models (LLMs) have demonstrated their ability to learn in-context, allowing them to perform various tasks based on a few input-output examples. However, the effectiveness of in-context learning is heavily reliant on the quality of the selected examples. In this paper, we propose a novel framework to iteratively train dense retrievers that can identify high-quality in-context examples for LLMs. Our framework initially trains a reward model based on LLM feedback to evaluate the quality of candidate examples, followed by knowledge distillation to train a bi-encoder based dense retriever. Our experiments on a suite of $30$ tasks demonstrate that our framework significantly enhances in-context learning performance. Furthermore, we show the generalization ability of our framework to unseen tasks during training. An in-depth analysis reveals that our model improves performance by retrieving examples with similar patterns, and the gains are consistent across LLMs of varying sizes. The code and data are available at https://github.com/microsoft/LMOps/tree/main/llm_retriever .

View on arXivView PDF

Code Implementations(1)

microsoft/LMOpsOfficial100%
MIT

General technology for enabling AI capabilities w/ LLMs and MLLMs

4,440377C, C++Dec 13, 20225 months agoMIT
agigptlanguage-modelllmlm+6 more

Similar Papers

Cite this paper

@article{wang2023learning,
  title  = {Learning to Retrieve In-Context Examples for Large Language Models},
  author = {Liang Wang and Nan Yang and Furu Wei},
  year   = {2023},
  eprint = {2307.07164},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2307.07164v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2307.07164.svg)](https://codeofpaper.com/paper/2307.07164)

Discussion