Attacker
We implement 12 attackers and categorize them by trigger type and accessibility. Here is the list of currently involved attack models.
(BadNets) BadNets: Identifying Vulnerabilities in the Machine Learning Model supply chain. Tianyu Gu, Brendan Dolan-Gavitt, Siddharth Garg. 2017. [paper]
(AddSent) A backdoor attack against LSTM-based text classification systems. Jiazhu Dai, Chuanshuai Chen. 2019. [paper]
(SynBkd) Hidden Killer: Invisible Textual Backdoor Attacks with Syntactic Trigger. Fanchao Qi, Mukai Li, Yangyi Chen, Zhengyan Zhang, Zhiyuan Liu, Yasheng Wang, Maosong Sun. 2021. [paper]
(StyleBkd) Mind the Style of Text! Adversarial and Backdoor Attacks Based on Text Style Transfer. Fanchao Qi, Yangyi Chen, Xurui Zhang, Mukai Li,Zhiyuan Liu, Maosong Sun. 2021. [paper]
(POR) Backdoor Pre-trained Models Can Transfer to All. Lujia Shen, Shouling Ji, Xuhong Zhang, Jinfeng Li, Jing Chen, Jie Shi, Chengfang Fang, Jianwei Yin, Ting Wang. 2021. [paper]
(TrojanLM) Trojaning Language Models for Fun and Profit. Xinyang Zhang, Zheng Zhang, Shouling Ji, Ting Wang. 2021. [paper]
(SOS) Rethinking Stealthiness of Backdoor Attack against NLP Models. Wenkai Yang, Yankai Lin, Peng Li, Jie Zhou, Xu Sun. 2021. [paper]
(LWP) Backdoor Attacks on Pre-trained Models by Layerwise Weight Poisoning. Linyang Li, Demin Song,Xiaonan Li, Jiehang Zeng, Ruotian Ma, Xipeng Qiu. 2021. [paper]
(EP) Be Careful about Poisoned Word Embeddings: Exploring the Vulnerability of the Embedding Layers in NLP Models. Wenkai Yang, Lei Li, Zhiyuan Zhang, Xuancheng Ren, Xu Sun, Bin He. 2021. [paper]
(NeuBA) Red Alarm for Pre-trained Models: Universal Vulnerability to Neuron-Level Backdoor Attacks. Zhengyan Zhang, Guangxuan Xiao, Yongwei Li, Tian Lv, Fanchao Qi, Zhiyuan Liu, Yasheng Wang, Xin Jiang, Maosong Sun. 2021. [paper]
(LWS) Turn the Combination Lock: Learnable Textual Backdoor Attacks via Word Substitution. Fanchao Qi, Yuan Yao, Sophia Xu, Zhiyuan Liu, Maosong Sun. 2021. [paper]
(RIPPLES) Weight Poisoning Attacks on Pre-trained Models. Keita Kurita, Paul Michel, Graham Neubig. 2020. [paper]
We summarize these attackers in the Table below, please refer to this paper for more details.
Base Attacker
- class openbackdoor.attackers.Attacker(poisoner: Optional[dict] = {'name': 'base'}, train: Optional[dict] = {'name': 'base'}, metrics: Optional[List[str]] = ['accuracy'], sample_metrics: Optional[List[str]] = [], **kwargs)[source]
The base class of all attackers. Each attacker has a poisoner and a trainer.
- Parameters:
- attack(victim: Victim, data: List, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim
- eval(victim: Victim, dataset: List, defender: Optional[Defender] = None)[source]
Default evaluation function (ASR and CACC) for the attacker.
- Parameters:
victim (
Victim) – the victim to attack.dataset (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the evaluation results.
- Return type:
- eval_poison_sample(victim: Victim, dataset: List, eval_metrics=[])[source]
Evaluation function for the poison samples (PPL, Grammar Error, and USE).
- Parameters:
victim (
Victim) – the victim to attack.dataset (
List) – the dataset to attack.eval_metrics (
List) – the metrics for samples.
- Returns:
the poisoned dataset.
- Return type:
List
EP Attacker
- class openbackdoor.attackers.EPAttacker(**kwargs)[source]
Attacker for EP
- attack(victim: Victim, dataset: List, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim
SOS Attacker
- class openbackdoor.attackers.SOSAttacker(**kwargs)[source]
Attacker for SOS
- attack(victim: Victim, dataset: List, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim
NeuBA Attacker
- class openbackdoor.attackers.NeuBAAttacker(from_scratch: Optional[bool] = False, **kwargs)[source]
Attacker for NeuBA
- attack(victim: Victim, data: List, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim
POR Attacker
- class openbackdoor.attackers.PORAttacker(from_scratch: Optional[bool] = False, **kwargs)[source]
Attacker for POR
- attack(victim: Victim, data: List, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim
LWP Attacker
- class openbackdoor.attackers.LWPAttacker(**kwargs)[source]
Attacker for LWP
- attack(victim: Victim, dataset: List, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim
LWS Attacker
- class openbackdoor.attackers.LWSAttacker(**kwargs)[source]
Attacker for LWS <https://aclanthology.org/2021.acl-long.377.pdf>
- attack(model: Victim, data: Dict, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim
- eval(victim, dataset: Dict, defender: Optional[Defender] = None)[source]
Default evaluation function (ASR and CACC) for the attacker.
- Parameters:
victim (
Victim) – the victim to attack.dataset (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the evaluation results.
- Return type:
RIPPLES Attacker
- class openbackdoor.attackers.RIPPLESAttacker(**kwargs)[source]
Attacker for RIPPLES
- attack(victim: Victim, dataset: List, config: Optional[dict] = None, defender: Optional[Defender] = None)[source]
Attack the victim model with the attacker.
- Parameters:
victim (
Victim) – the victim to attack.data (
List) – the dataset to attack.defender (
Defender, optional) – the defender.
- Returns:
the attacked model.
- Return type:
Victim