Set up the demo retriever for evaluation
mainTo run evaluations using an online retrieval model, you can use a subset of Wikipedia. This requires downloading a demo corpus and embeddings (approx. 9GB).
Clone the repository and run the download script:
git clone git@github.com:AkariAsai/self-rag.git cd retrieval_lm bash download_demo_corpus.shUse the
Retrieverclass to search for documents and feed them into the model prompt.
from passage_retrieval import Retriever
# Initialize retriever
retriever = Retriever({})
# Setup demo retriever with specific paths
retriever.setup_retriever_demo(
"facebook/contriever-msmarco",
"enwiki_2020_intro_only/enwiki_2020_dec_intro_only.jsonl",
"enwiki_2020_intro_only/enwiki_dec_2020_contriever_intro/*",
n_docs=5,
save_or_load_index=False
)
# Search for documents
query_3 = "What is overfitting?"
retrieved_documents = retriever.search_document_demo(query_3, 5)
# Format prompts for the model using retrieved docs
# Note: format_prompt is defined in the quickstart section
prompts = [format_prompt(query_3, doc["title"] + "\n" + doc["text"]) for doc in retrieved_documents]
preds = model.generate(prompts, sampling_params)
# Display results
top_doc = retriever.search_document_demo(query_3, 1)[0]
print("Reference: {0}\nModel prediction: {1}".format(top_doc["title"] + "\n" + top_doc["text"], preds[0].outputs[0].text))