This guide walks you through everything you need to run the Heron AI Security baseline experiment from scratch: cloning the repository, setting up a virtual environment, installing all dependencies, and executing the experiment withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Antisource/heronaisec/llms.txt
Use this file to discover all available pages before exploring further.
python main.py. The full pipeline — dataset loading, BadNet poisoning, DistilBERT training, progressive clean fine-tuning, metric collection, and figure generation — runs from a single entry point.
Prerequisites
Before you begin, make sure your environment meets the following requirements:- Python 3.8 or higher — check with
python --version - Git — check with
git --version - CUDA-capable GPU (optional but recommended) — training DistilBERT on CPU is possible but significantly slower; see the note in Expected Output
Steps
Clone the repository
Clone the Heron AI Security repository from GitHub and navigate into the project directory.
Create a virtual environment
Create an isolated Python environment so that the project’s dependencies do not conflict with other projects on your system.Then activate the environment for your operating system:Your shell prompt will update to show
- Linux / macOS
- Windows
(.venv) when the environment is active.Install dependencies
Install all required packages from the pinned requirements file.The
requirements.txt file is organised into the following dependency groups:| Group | Packages |
|---|---|
| Deep Learning | torch>=2.7,<3.0 |
| Hugging Face | transformers, datasets, accelerate, evaluate |
| Scientific Computing | numpy, pandas, scikit-learn |
| Visualization | matplotlib>=3.10,<4.0 |
| Configuration | PyYAML>=6.0,<7.0 |
| Utilities | tqdm>=4.67,<5.0 |
Run the baseline experiment
Launch the complete baseline experiment with a single command.
main.py is the repository entry point. It first checks for a CUDA-capable GPU via torch.cuda.is_available() and prints either Using GPU: <device name> or Using CPU, then calls run_baseline() from experiments/baseline.py. The baseline function loads the experiment configuration from configs/baseline.yaml, prepares the SST-2 dataset, trains a backdoored DistilBERT model using BadNet poisoning, applies progressive clean fine-tuning at six intervention strengths (0 % → 20 % → 40 % → 60 % → 80 % → 100 %), evaluates the model after each stage, and writes all outputs to a timestamped results directory.Expected Output
When the experiment completes, a timestamped directory is created underresults/. The directory name is derived from the experiment name and a wall-clock timestamp recorded at the start of the run.
| Output | Description |
|---|---|
metrics.csv | Tabular metrics (ASR, Clean Accuracy, Mean Trigger Confidence, Retention Ratio) for every intervention stage |
persistence_curve.png | Main result figure showing how all four metrics evolve across progressive fine-tuning stages |
reviewer_intervention.png | Secondary figure generated when the reviewer experiment is enabled in the configuration |
LOAD_FROM_CHECKPOINT = True is the default value at the top of experiments/baseline.py. This tells the experiment orchestrator to load pre-trained model weights from an existing checkpoint directory instead of training from scratch.If you are running the experiment for the first time and do not have saved checkpoints, set this flag to False before running:LOAD_FROM_CHECKPOINT = False, the experiment will train the initial backdoored model and all intervention checkpoints from scratch, which will take considerably longer depending on your hardware.Prototype subset active by defaultThe
train_backdoored_model function in experiments/baseline.py includes a .select(range(5000)) call that limits the training dataset to 5 000 examples for faster iteration during prototyping. This line is active in the repository as checked in. Remove it for a full-scale experiment, or reduce the number of training epochs in configs/baseline.yaml to keep iteration times manageable on slower hardware.Next Steps
Running Experiments
Learn how to configure and run experiments using the YAML-driven pipeline, including how to adjust poison rates, intervention stages, and model checkpoints.
Configuration Reference
Explore every field in
configs/baseline.yaml — dataset, model, attack, training, intervention, reviewer, evaluation, and visualization settings.