We use uv for dependency and environment management.
The project has been tested with Python 3.10.19.
If you have not installed uv, run:
curl -LsSf https://astral.sh/uv/install.sh | shor
pip install uvSince the project already includes pyproject.toml and uv.lock, you can directly create and synchronize the environment with:
uv syncThis will automatically:
- create a virtual environment,
- install the correct Python dependencies,
- and reproduce the locked package versions from
uv.lock.
Activate the environment if needed:
source .venv/bin/activate.venv\Scripts\Activate.ps1We provide a run.sh script to reproduce experiments across different datasets, backdoor attack methods, and scoring functions.
agnewsYelpHSOL
badnetsaddsentstylebkdsynbkd
md(Mahalanobis Distance)badacts
OSCS
roberta-base(default)bert-base-uncased(optional)
First, ensure the script is executable:
chmod +x run.shThen execute:
bash run.shThe script automatically iterates over all combinations of:
- scoring functions,
- backdoor attack methods,
- and datasets,
and runs main.py with the corresponding configurations.
The core command executed by run.sh is:
python main.py \
--dataset_name agnews \
--poisoner_name <poisoner_name> \
--method OSCS \
--score_name <score_name> \
--model_name roberta-base \
--T 20000To switch from RoBERTa to BERT, modify the model name in run.sh:
--model_name bert-base-uncasedTrained models and intermediate results are saved to:
./modelsYou may change the output directory by modifying MODEL_SAVE_PATH in run.sh.