This is the official repository for our ACL 2024 (findings) paper Unraveling and Mitigating Retriever Inconsistencies in Retrieval-Augmented Large Language Model. We propose Ensemble of Retrievers (EoR), a trainable generate-then-rerank framework that first generates answers from different retrievers (we implement 16 different retrievers including retreival-free) and then select the best one out of them. Our experiments demonstrate that EoR can adaptively retrieve from different knowledge sources and boost the performance of Retrieval-Augmented Language Models.
Our framework is composed of three parts: Controller, Generator and Evaluator. The Controller takes the responsibility to retrieve and process differet knowledge (i.e. implementing different retrievers) and the Generator generate responses for each retriever. Then the Evaluator evaluate all responses and select the best one as the final answer.
The Controller consists of five different modules, three for retrieving (Web, Wiki, Gendoc) and two for knowledge processing (Contriever and Summarizer). The Evaluator consisted of two different modules: VoterModule and ScorerModule.
Please note that the Web module conducts on-time search-engine retrieval. Hence the results might be different from our own experiments presented in the paper. We will release our intermediate results in the future.
conda create -n EoR python=3.9
pip3 install torch
conda install -c conda-forge openjdk=11
conda install -c pytorch faiss-cpu=1.7.4 mkl=2021
pip install -r requirements.txt
Other models and files needed:
from pyserini.search.faiss import FaissSearcher, DprQueryEncoder
en_searcher = FaissSearcher.from_prebuilt_index('wikipedia-dpr-multi-bf', DprQueryEncoder('facebook/dpr-question_encoder-multiset-base'))
yaml Config file
└───LLMConfig
└───llm5
│───model_name: en_paragraph_encoder
│───model_path: **change to your cached path here**
yaml Config file
└───LLMConfig
└───[anything is ok, not important]
│───model_name: [the name to represent this model]
│───model_path: [path used for loading the model using .from_pretrained in huggingface]
│───model_class: [the model class used before .from_pretrained in huggingface, such as 'AutoModel']
│───fp16: [Whether use half precision]
│───tokenizer_path: [path used for loading the tokenizer using .from_pretrained in huggingface]
│───tokenizer_class: [tokenizer class used before .from_pretrained in huggingface]
yaml Config file
└───ModuleConfig
└───[the module name you want to change the base model used]
│───en_model_name: [put the "model name" in LLMConfig here]
Download the datasets NQ, TriviaQ, WebQ from this url, then run the following code to process the data:
python data/datasets/process.py -d [path to the data jsonl file] -o [path to save the processed data]
to sample the 500 examples for gpt-3.5, run the following code:
python data/datasets/data_sampler.py -d [path to the processed data jsonl file] -o [path to save the sampled data]
we use yaml config file to control the parameters in our framework. you can find them in 'config/'.
you can add or modify the module config under "ModuleConfig" to change the basic configuration for the seven basic modules
'LLMconfig' controls the loading configurations for the models used in this framework.
'ControlConfig' controls the configuration of different retrievers.
'ControllerConfig','GeneratorConfig' and 'EvaluatorConfig' controlls what modules to be used.
HF_DATASETS_OFFLINE=1 TRANSFORMERS_OFFLINE=1 python run.py -c [path to the config file]
python run_evaluate.py -r [path to the result json file ] -o [path to save evaluation result] -n [dataset_name] -m [metrics to evaluate]
for quick search, please cache all intermediate results of each module when generating answers.
Notebly, you can find a file named "controller_result.json" in your cached result directory which cached all processed documents. You can specify this file's name to skip all modules in the Controller.
python run_search_weight.py -c [path of config file] -d [name of dataset to evaluate] -m [model name] -r [path of cached result dir] -t [path of saved query for train data] -cn [file name of the cached controller result file] --test_path [path of saved query for test data] --test_cached_path [path of cached test result dir] -o [path to save parameter search result]
11 commits
2 commits
Python
100.0%
This is the official repository for our ACL 2024 (findings) paper Unraveling and Mitigating Retriever Inconsistencies in Retrieval-Augmented Large Language Model. We propose Ensemble of Retrievers (EoR), a trainable generate-then-rerank framework that first generates answers from different retrievers (we implement 16 different retrievers including retreival-free) and then select the best one out of them. Our experiments demonstrate that EoR can adaptively retrieve from different knowledge sources and boost the performance of Retrieval-Augmented Language Models.
Our framework is composed of three parts: Controller, Generator and Evaluator. The Controller takes the responsibility to retrieve and process differet knowledge (i.e. implementing different retrievers) and the Generator generate responses for each retriever. Then the Evaluator evaluate all responses and select the best one as the final answer.
The Controller consists of five different modules, three for retrieving (Web, Wiki, Gendoc) and two for knowledge processing (Contriever and Summarizer). The Evaluator consisted of two different modules: VoterModule and ScorerModule.
Please note that the Web module conducts on-time search-engine retrieval. Hence the results might be different from our own experiments presented in the paper. We will release our intermediate results in the future.
conda create -n EoR python=3.9
pip3 install torch
conda install -c conda-forge openjdk=11
conda install -c pytorch faiss-cpu=1.7.4 mkl=2021
pip install -r requirements.txt
Other models and files needed:
from pyserini.search.faiss import FaissSearcher, DprQueryEncoder
en_searcher = FaissSearcher.from_prebuilt_index('wikipedia-dpr-multi-bf', DprQueryEncoder('facebook/dpr-question_encoder-multiset-base'))
yaml Config file
└───LLMConfig
└───llm5
│───model_name: en_paragraph_encoder
│───model_path: **change to your cached path here**
yaml Config file
└───LLMConfig
└───[anything is ok, not important]
│───model_name: [the name to represent this model]
│───model_path: [path used for loading the model using .from_pretrained in huggingface]
│───model_class: [the model class used before .from_pretrained in huggingface, such as 'AutoModel']
│───fp16: [Whether use half precision]
│───tokenizer_path: [path used for loading the tokenizer using .from_pretrained in huggingface]
│───tokenizer_class: [tokenizer class used before .from_pretrained in huggingface]
yaml Config file
└───ModuleConfig
└───[the module name you want to change the base model used]
│───en_model_name: [put the "model name" in LLMConfig here]
Download the datasets NQ, TriviaQ, WebQ from this url, then run the following code to process the data:
python data/datasets/process.py -d [path to the data jsonl file] -o [path to save the processed data]
to sample the 500 examples for gpt-3.5, run the following code:
python data/datasets/data_sampler.py -d [path to the processed data jsonl file] -o [path to save the sampled data]
we use yaml config file to control the parameters in our framework. you can find them in 'config/'.
you can add or modify the module config under "ModuleConfig" to change the basic configuration for the seven basic modules
'LLMconfig' controls the loading configurations for the models used in this framework.
'ControlConfig' controls the configuration of different retrievers.
'ControllerConfig','GeneratorConfig' and 'EvaluatorConfig' controlls what modules to be used.
HF_DATASETS_OFFLINE=1 TRANSFORMERS_OFFLINE=1 python run.py -c [path to the config file]
python run_evaluate.py -r [path to the result json file ] -o [path to save evaluation result] -n [dataset_name] -m [metrics to evaluate]
for quick search, please cache all intermediate results of each module when generating answers.
Notebly, you can find a file named "controller_result.json" in your cached result directory which cached all processed documents. You can specify this file's name to skip all modules in the Controller.
python run_search_weight.py -c [path of config file] -d [name of dataset to evaluate] -m [model name] -r [path of cached result dir] -t [path of saved query for train data] -cn [file name of the cached controller result file] --test_path [path of saved query for test data] --test_cached_path [path of cached test result dir] -o [path to save parameter search result]
11 commits
2 commits
Python
100.0%