in-context-ralm
In-Context Retrieval-Augmented Language Models Experiment Reproduction
GraphCanon updated 3w · GitHub synced 3w
Decision brief
A Python implementation for reproducing WikiText-103 experiments using AI21 Labs' RALM method, focusing on retrieval-enhanced language models.
Good fit when
- When aiming to reproduce WikiText-103 results with retrieval-augmented language models as specified in the AI21 Labs paper.
- For model evaluations where context-rich retrieval systems improve language generation tasks.
Avoid when
- If working strictly on general-purpose language modeling without utilizing retrieval mechanisms for augmenting contextual information.
- When Python 3.8 compatibility and specific library versions (Transformers, Pyserini) are not alignable with the project environment.
Observed Jul 12, 2026 · Source: enrich:decision_facts
Verify the decision
Maintenance and security
Full trust report- Maintenance
- Archived (955d since push)
- As of 3w
- Provenance
- Not a fork · Organization account
- As of 3w
- Security (OSV)
- 75 low (75 low)
- As of 1mo
Public GitHub metadata and optional OSV scans. Signals, not a guarantee. Trust methodology.
Install
pip install in-context-ralm PyPISimilar tools
Same-category neighbours. No typed graph edges are catalogued for this tool yet.
Evidence and technical details
Sourced facts, taxonomy, compatibility claims, README excerpt, and machine-readable endpoints.
Overview
Repository for reproducing experiments on WikiText-103 using retrieval-augmented language models as described in the AI21 Labs paper.
Capability facts
- Languages
- python
Source: github.language · Aug 1, 2026
Categories
Compatibility
Sourced claims from the README excerpt - not unsourced marketing copy.
Source: README excerpt (regex_v1, Aug 1, 2026)
We test it on Python 3.8.Source link
Tags
README
In-Context Retrieval-Augmented Language Models
This repo contains the code for reproducing the experiments on WikiText-103 from AI21 Labs' paper In-Context Retrieval-Augmented Language Models (In-Context RALM), to appear in the Transactions of the Association for Computational Linguistics (TACL).
Our code is mainly based on the Transformers and Pyserini libraries.
We test it on Python 3.8.
Table of Contents
- Setup
- Retrieval
- Evaluation
- Language Models
- Evaluate models w/o retrieval
- Evaluate models with retrieval
- Evaluate models with reranking
- Question Answering Experiments
- Citation
Setup
To install the required libraries in our repo, run:
pip install -r requirements.txt
To have a Pytorch version specific to your CUDA, install your version before running the above command.
Retrieval
BM25
Our BM25 preparation script works with Pyserini, so Java 11 is required - see their installation guide.
If you have Java 11 installed, make sure your JAVA_HOME environment variable is set to the correct path.
On a Linux system, the correct path might look something like /usr/lib/jvm/java-11.
Then run:
python prepare_retrieval_data.py \
--retrieval_type sparse \
--tokenizer_name $MODEL_NAME \
--max_length 1024 \
--dataset_path wikitext \
--dataset_name wikitext-103-v1 \
--dataset_split [validation, test] \
--index_name wikipedia-dpr \
--forbidden_titles_path ralm/retrievers/wikitext103_forbidden_titles.txt \
--stride 4 \
--output_file $RETRIEVAL_FILE \
--num_tokens_for_query 32 \
--num_docs 16
Evaluation
List of Language Models
In the paper, we give the results for the following models (replace $MODEL_NAME with one of those).
Note that the larger models may need model parallelism (on a 40GB A100, we used model parallelism for OPT-30B and OPT-66B).
See details below on how to apply this option.
- GPT-2:
gpt2,gpt2-medium,gpt2-large,gpt2-xl - GPT-Neo:
EleutherAI/gpt-neo-1.3B,EleutherAI/gpt-neo-2.7B,EleutherAI/gpt-j-6B - OPT:
facebook/opt-125m,facebook/opt-350m,facebook/opt-1.3b,facebook/opt-2.7b,facebook/opt-6.7b,facebook/opt-13b,facebook/opt-30b,facebook/opt-66b
Evaluate models w/o retrieval
To run evaluation on models without retrieval, please use the following command (you can increase stride to 32 for faster evaluation):
python eval_lm.py \
--model_name $MODEL_NAME \
--dataset_path wikitext \
--dataset_name wikitext-103-v1 \
--dataset_split [validation, test] \
--output_dir $OUTPUT_DIR \
--stride 4 \
--max_length 1024 \
[--model_parallelism]
Evaluate models with retrieval:
To run models with retrieval, use the $RETRIEVAL_FILE output from the prepare_retrieval_data.py script:
python eval_lm.py \
--model_name $MODEL_NAME \
--dataset_path wikitext \
--dataset_name wikitext-103-v1 \
--dataset_split [validation, test] \
--output_dir $OUTPUT_DIR \
--stride 4 \
--max_length 1024 \
[--model_parallelism] \
--retrieved_file $RETRIEVAL_FILE
Note: Our main retrieval flow assumes you want to use the top-scored passage from your retrieval file (--ranking_strategy first).
Reranking
Currently, we support logprob (the zero-shot method described in subsection 6.1) and oracle (to understand the potential gains from reranking).
For reranking, first you need to make sure you run the retrieval script with num_docs=16 (or any other number you want to rerank on).
If you enable multiple GPUs, data parallelism will automatically be a
For agents
This page has a .md twin and JSON over the API.