This is the code repository for our ECIR reproducibility paper submission.
datasets/
contains the datasets files used in the experiments.results/
contains the results of the experiments.scripts/
contains the scripts to run the experiments.utils/
contains the utility functions used in the experiments.
The datasets used in the experiments are from the BEIR library. The datasets are stored in the datasets/
folder. These datasets will download automatically when you run the code.
- Python ,PyTorch , numpy, pandas, beir,transformers, sentence_transformers, sklearn, wandb
- If you do not want to use wandb, you can comment out all code with wandb in the code.
- You need to install the beir library(https://github.com/beir-cellar/beir)
Things need for the experiments in RQ1:
- 1,
embedding_index.py
is used to index the embeddings of the corpus, and save the retrieval results by BEIR. - 2.1,
hotflip_raw.py
is used to generate the adversarial examples by hotflip (Zhong et al., 2023). - 2.2,
hotflip_attack_ours.py
is used to generate the adversarial examples by hotflip (Zhong et al., 2023) with our pipeline optimizing strategy (Mean embedding). - 3,
evaluate_attack.py
is used to evaluate the attack performance of the adversarial examples. The retrieval results are saved inresults/
. - 4,
attack_results_statistics.py
is used to calculate the statistics of the attack results.
Things need for the experiments in RQ2:
- 1, repeat the steps in RQ1 to generate the adversarial examples with all 7 retrievers.
- 2,
evaluate_attack.py
is used to evaluate the attack performance of the adversarial examples. The retrieval results are saved inresults/
. - 3,
transfer_attack_statical.py
is used to calculate the statistics of the attack results of black-box attacks.
Things need for the experiments in RQ3:
- 1,
hotflip_ours_attack_corpus.py
is used for the corpus poisoning attack with our pipeline optimizing strategy (Mean embedding).
- 1, Run
sbatch scripts/embedding_index.sh
to get the retrieval results of the all datsaets with all retrievers. The retrieval results are saved inresults/beir_result
. - 2, Run
sbatch scripts/generate_hotflip_multi_raw.sh
to generate the adversarial examples by hotflip (Zhong et al., 2023). The adversarial examples are saved inresults/hotflip_raw-generate
. - 3, Run
sbatch scripts/generate_hotflip_multi.sh
to generate the adversarial examples by hotflip (Zhong et al., 2023) with our pipeline optimizing strategy (Mean embedding). The adversarial examples are saved inresults/hotflip-generate
. - 4, Run
sbatch scripts/evaluate_attack.sh
to evaluate the attack performance of the adversarial examples. The results are saved inresults/attack_results
. - 5, Run
python attack_results_statistics.py
to calculate the statistics of the attack results.
- 1, Since we have already generated the adversarial examples in RQ1, we do not need to repeat the steps in RQ1.
- 2, Run
sbatch scripts/transfer_attack.sh
. The retrieval results are saved inresults/attack_results/hotflip
andresults/attack_results/hotflip_raw
. - 3, Run
python transfer_attack_statical.py --method hotflip_raw
andpython transfer_attack_statical.py --method hotflip
to calculate the statistics of the attack results of black-box attacks. Remember to change the method tohotflip_raw
andhotflip
respectively. And changeseed_list = [1999]
only fork_list=[10]
in the evaluationhotflip_raw
method.
- 1, Run
sbatch scripts/attack_corpus_ous.sh
to generate the adversarial passages for the corpus poisoning attack. The results are saved inresults_corpus_attack/hotflip-generate
. - 2, When you finish the code, they will output the evaluation results directly. Just record the results.
The maximum number of iterations
In this Figure , we can observe that a larger