GithubHelp home page GithubHelp logo

lancopku / dan Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 0.0 18 KB

[Findings of EMNLP 2022] Expose Backdoors on the Way: A Feature-Based Efficient Defense against Textual Backdoor Attacks

License: MIT License

Python 100.00%
ai-safety backdoor-attacks backdoor-defense natural-language-processing

dan's Introduction

DAN: Distance-Based Anomaly Score for Textual Backdoor Defense

This is the official code of our EMNLP 2022 (findings) paper Expose Backdoors on the Way: A Feature-Based Efficient Defense against Textual Backdoor Attacks.

Requirements

Python: 3.8.0

To install the dependencies, run

pip install -r requirements.txt

For the datasets used in our paper, please refer to the code of Embedding Poisoning.

For the posioned models, please obtain the poisoned weights following the intrsuction of the code of the attacking methods developed by previous researchers:

Usage

For instance, there is a BERT model for SST-2 classification posioned by the embedding poisoing attack with a rare word trigger mb and the target class 1:

1. Feature Extraction

Run the following command:

python extract_embeddings.py --model_path ../Embedding-Poisoning/saved_models/sst-2/badnet_rw_mb_ls --test_data_path ./sentiment_data/sst-2/test.tsv --constructing_data_path ./sentiment_data/sst-2/dev.tsv   --output_dir ./log/embeddings/dan/sst-2/badnet_rw_mb_ls --batch_size 128 --backdoor_triggers mb --protect_label 1 --backdoor_trigger_type sentence

Notes: If you want to insert multiple trigger words, like mb and bb, concat them with a comma: --backdoor_triggers mb,bb; if you want to experiment on a posioned model embedded with a sentence trigger, just use --backdoor_trigger_type sentence and pass the trigger sentence string to --backdoor_triggers.

2. DAN Score Calculation and Evaluation

Run the following command:

python evaluate_dan.py --std --agg mean --score_ensemble  --input_dir ./log/embeddings/dan/sst-2/badnet_rw_mb_ls

Meaning of the arguments:

  • score_ensemble: turn on the layer-wise score aggreation operation;
  • std: turn on the normaliztion operation before aggreation;
  • agg: the aggregation operator (mean or min)

Citation

If you find this repository to be useful for your research, please consider citing.

@inproceedings{chen-etal-2022-expose,
    title = "Expose Backdoors on the Way: A Feature-Based Efficient Defense against Textual Backdoor Attacks",
    author = "Chen, Sishuo  and
      Yang, Wenkai  and
      Zhang, Zhiyuan  and
      Bi, Xiaohan  and
      Sun, Xu",
    booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2022",
    month = dec,
    year = "2022",
    address = "Abu Dhabi, United Arab Emirates",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2022.findings-emnlp.47",
    pages = "668--683"
}

Acknowledgement

This repository relies on resources from Embedding-Poisoning, RAP, NeuBA, BadPre, and Huggingface Transformers. We thank the original authors for their open-sourcing.

dan's People

Contributors

pkucss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dan's Issues

Question about RAP

Hello, may I ask if you can disclose the relevant code on RAP? The RAP I reproduced was poor, so I wanted to see how other people reproduced it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.