Perturb-and-compare Approach for Detecting Out-of-distribution Samples in Constrained Access Environments
This repossitory contains the code for the paper Perturb-and-compare Approach for Detecting Out-of-distribution Samples in Constrained Access Environments (ECAI 2024).
Accessing machine learning models through remote APIs has been gaining prevalence following the recent trend of scaling up model parameters for increased performance. Even though these models exhibit remarkable ability, detecting out-of-distribution (OOD) samples remains a crucial safety concern for end users as these samples may induce unreliable outputs from the model. In this work, we propose an OOD detection framework, MixDiff, that is applicable even when the model's parameters or its activations are not accessible to the end user. To bypass the access restriction, MixDiff applies an identical input-level perturbation to a given target sample and a similar in-distribution (ID) sample, then compares the relative difference in the model outputs of these two samples. MixDiff is model-agnostic and compatible with existing output-based OOD detection methods. We provide theoretical analysis to illustrate MixDiff's effectiveness in discerning OOD samples that induce overconfident outputs from the model and empirically demonstrate that MixDiff consistently enhances the OOD detection performance on various datasets in vision and text domains.
conda env create -f environment.yml
conda activate mixdiff
Place the datasets as below:
-
CIFAR10
- The dataset is automatically downloaded when the code is run.
-
CIFAR100
- The dataset is automatically downloaded when the code is run.
-
CIFAR10+
- The dataset is automatically downloaded when the code is run.
-
CIFAR50+
- The dataset is automatically downloaded when the code is run.
-
TinyImageNet
- Run
tinyimagenet.sh
script indata
directory.
- Run
Evaluate MixDiff's performance when the model outputs are logits.
bash mixup/scripts/logit/mixdiff_logit.sh
Run the script below after replacing OOD_METHOD
with one of the following names: entropy
, msp
.
bash mixup/scripts/prob/mixdiff_prob_{OOD_METHOD}.sh
Evaluate the setup where oracle samples are used as auxiliary samples.
bash mixup/scripts/prob/mixdiff_entropy_orc.sh
Evaluate the setup where random ID samples are used as auxiliary samples.
bash mixup/scripts/prob/mixdiff_entropy_rnd_id.sh
Evaluate using oracle samples as auxiliary samples.
bash mixup/scripts/label/onehot_agmax_orc.sh
Evaluate using random ID samples as auxiliary samples.
bash mixup/scripts/label/onehot_agmax_rnd_id.sh
Evaluate MixDiff's performance when the model outputs are last layer activation.
bash mixup/scripts/embed/mixdiff_embedding.sh
Evaluate output-based baseline OOD scoring functions (MSP, MLS, etc.) on benchmark datasets.
bash mixup/scripts/baselines/baselines.sh
Evaluate baseline under various adversarial attack scenarios.
bash mixup/scripts/adv_attack/baselines.sh
Evaluate MixDiff+Entropy under various adversarial attack scenarios.
bash mixup/scripts/adv_attack/entropy_orc_mixdiff.sh
Evaluate MixDiff only under various adversarial attack scenarios.
bash mixup/scripts/adv_attack/entropy_orc_mixdiff_only.sh
Evaluate MixDiff only on clean samples.
bash mixup/scripts/adv_attack/entropy_orc_mixdiff_only_clean.sh
-
ACID
- Download the dataset from the official repository.
- Place
data/acid/customer_training.csv
anddata/acid/customer_testing.csv
under the directorydata/acid/
.
-
CLINIC150
- Download the dataset from the official repository.
- Place
data_full.json
under the directorydata/clinc150
.
-
TOP
- Download the dataset from the link provided in the paper.
- Unzip the file under the directory
data/top
.
-
Banking77
- This dataset is automatically downloaded when the code is run.
Run the script after replacing DATASET_NAME
with one of the following names: clinic150
, banking77
, acid
, top
. This will train intent classification models for MixDiff hyperparameter search as well as the final OOS detection performance evaluation.
bash text_classification/scripts/train_{DATASET_NAME}.sh
bash mixup_text/scripts/run_val.sh
Run evaluation on the test split by selecting appropriate values in the script below.
bash mixup_text/scripts/run_test.sh
Run MLS, MSP, Energy and entropy OOS detection baselines by using the script below.
bash mixup_text/scripts/run_baselines.sh
TODO
We built our experiment pipeline from the codebase of ZOC repository. We thank the authors of "Zero-Shot Out-of-Distribution Detection Based on the Pre-trained Model CLIP" for sharing their code.