MCPcopy Index your code
hub / github.com/OSU-NLP-Group/In-Context-Reranking

github.com/OSU-NLP-Group/In-Context-Reranking @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
117 symbols 320 edges 10 files 33 documented · 28%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

In-Context-Reranking

Code and data for paper Attention in Large Language Models Yields Efficient Zero-Shot Re-Rankers.

We present in-context re-ranking (ICR), an efficient re-ranking method that directly leverages the attention pattern of LLMs for zero-shot re-ranking. By reading the LLM’s mind, ICR dramatically cuts the complexity of re-ranking $N$ documents from $O(N)$ ~ $O(N \log N)$ down to O(1) with better re-ranking performance, especially on more challenging tasks.

Data Preparation

BEIR datasets

Prepare BM25 retrieval results for BEIR datasets with src/bm25_retrieval.ipynb (You need to setup Pyserini). The retrieval result will be stored in retriever_outpout/.

Multi-hop datasets

Download ColBERTv2 top-20 retrieval results for multi-hop datasets here and put them in retriever_outpout/.

Custom dataset

Process your own data into the following json format:

[
  {
    "idx": "idx will be used to retrieve qrel records",
    "question": "query for retrieval or QA",
    "paragraphs":[
      {
        "idx": "idx of documents",
        "title": "title of document",
        "paragraph_text": "text of document",
        "is supporting": "true/false, whether the document is a target for retrieval",
      },
      {},
    ]
  },
  {},
]

Experiments

We provide the scripts for reproducing our experiments:

bash run_icr_beir.sh
bash run_icr_multihop.sh

Citation

If you find this work helpful, please consider citing our paper:

@misc{chen2024attentionlargelanguagemodels,
      title={Attention in Large Language Models Yields Efficient Zero-Shot Re-Rankers}, 
      author={Shijie Chen and Bernal Jiménez Gutiérrez and Yu Su},
      year={2024},
      eprint={2410.02642},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2410.02642}, 
}

Core symbols most depended-on inside this repo

update
called by 13
src/custom/custom_cache.py
score_documents
called by 7
src/in_context_reranker.py
_prepare_input_for_document_retrieval
called by 7
src/in_context_reranker.py
repeat_kv
called by 7
src/custom/custom_modeling_mistral.py
rerank
called by 4
src/rank_gpt_reranker.py
repeat_kv
called by 4
src/custom/custom_modeling_llama.py
apply_rotary_pos_emb
called by 3
src/custom/custom_modeling_llama.py
apply_rotary_pos_emb
called by 3
src/custom/custom_modeling_mistral.py

Shape

Method 80
Class 25
Function 10
Route 2

Languages

Python100%

Modules by API surface

src/custom/custom_modeling_llama.py50 symbols
src/custom/custom_modeling_mistral.py43 symbols
src/in_context_reranker.py10 symbols
src/rank_gpt_reranker.py8 symbols
src/custom/custom_cache.py4 symbols
src/bm25_retrieval.py1 symbols
experiments.py1 symbols

For agents

$ claude mcp add In-Context-Reranking \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact