Machine Learning Adversarial Attacks and Defenses
Introduction
Machine learning has revolutionized many applications and industries in recent years, enabling computers to learn patterns and make decisions from data. However, machine learning models are vulnerable to adversarial attacks – inputs that are intentionally designed to fool the model and cause it to make incorrect predictions. As machine learning is increasingly deployed in safety-critical applications like self-driving cars, medical diagnosis, and malware detection, it is crucial to understand the risks posed by adversarial attacks and develop defenses against them.
In this article, we will dive deep into adversarial attacks on machine learning, exploring what they are, the different types of attacks, popular attack methods, and the impact adversarial examples can have. We will also discuss various defense strategies that have been proposed to make machine learning models more robust to adversarial attacks. Let‘s get started!
What are Adversarial Attacks?
Adversarial attacks are inputs to machine learning models that an attacker has intentionally designed to cause the model to make a mistake. They are called "adversarial" because they are crafted by an adversary with the goal of misleading the model. Adversarial examples are often imperceptible to humans, but cause the model to misclassify them with high confidence.
For example, consider an image classifier trained to distinguish between pandas and gibbons. An attacker could add a small amount of carefully constructed noise to an image of a panda that fools the classifier into classifying it as a gibbon with high confidence, even though the image still looks like a panda to human eyes.
Adversarial attacks pose a serious threat to machine learning systems because they exploit the fact that models often rely on brittle and unstable features to make predictions, rather than the high-level semantic content like humans do. By manipulating these low-level features in subtle ways, an attacker can break a model that otherwise seems to be performing well.
Types of Adversarial Attacks
There are many different types of adversarial attacks that target machine learning models in different ways:
Evasion Attacks
Evasion attacks involve modifying input data at test time to evade detection by a deployed model. The attacker starts with a sample that the model correctly classifies, and makes small modifications to it until the model classifies it as a different class. For example, spammers and hackers often try to evade detection by obfuscating the content of spam emails and malware.
Poisoning Attacks
Poisoning attacks target the model training process by contaminating the training data in order to influence the learned model itself. By inserting carefully crafted samples into the training data, the attacker can degrade the model‘s performance or cause it to learn specific false behaviors. This is a concern especially with models trained on user-generated data which attackers could submit malicious data to.
Impersonation Attacks
In an impersonation attack, the attacker generates adversarial examples that mimic authorized or trusted users in order to fool access control or authentication systems. For example, an attacker could construct a sample that matches an authorized user‘s biometric data in order to gain unauthorized access.
Inversion Attacks
Model inversion attacks aim to reconstruct the private data that was used to train a model, revealing sensitive information about individuals. For example, an attacker could recover images of faces used to train a facial recognition model. Inversion attacks show that models can potentially memorize and leak their training data.
Membership Inference Attacks
Membership inference attacks involve determining whether a given data sample was part of a model‘s training set or not. This can reveal if an individual‘s data was used to train a model, compromising privacy. Membership inference takes advantage of the fact that models often perform better on data they were trained on.
Model Stealing
In a model stealing attack, the attacker aims to reconstruct a machine learning model by querying it and observing its outputs. Given enough queries, the attacker can extract the knowledge contained in the model and reuse it, even if the model itself is confidential. This is a threat to the intellectual property of model owners.
Black-box vs White-box Attacks
Adversarial attacks can also be categorized based on how much knowledge the attacker has about the model.
In a white-box setting, the attacker has full access to the model, including its architecture, parameters, and training data. This makes it easier to craft effective adversarial examples, as the attacker can compute gradients and probe the model‘s weaknesses.
In a more realistic black-box scenario, the attacker can only query the model as a black-box and observe its output predictions, without any other information about the model internals. Black-box attacks are more difficult, as the attacker must either try to approximate the model‘s gradients or use a substitute model to generate transferable adversarial examples. However, studies have shown that black-box attacks can still be effective, especially when using techniques like ensemble attacks and query-efficient optimization.
Adversarial Attack Methods
Many adversarial attack methods have been proposed that can generate adversarial examples to fool machine learning models. Here are some of the most widely-studied attacks:
Gradient-based Methods
Gradient-based methods compute the gradient of the model‘s loss function with respect to the input, and perturb the input in the direction that maximizes the loss. The Fast Gradient Sign Method (FGSM) is one of the first and simplest attacks, which adds the sign of the gradient to the input. Iterative methods like the Basic Iterative Method (BIM) and Projected Gradient Descent (PGD) take multiple gradient steps to produce more effective adversarial examples.
Optimization-based Methods
Optimization-based methods formulate the adversarial attack as an optimization problem and find the perturbation that maximally fools the model subject to a constraint on the perturbation size. Carlini & Wagner (C&W) attacks are a powerful class of optimization-based attacks that can defeat many defenses. Elastic-net attacks use elastic-net regularization to produce sparse perturbations.
Score-based Methods
Score-based methods use the model‘s output scores/probabilities rather than its gradient to guide the adversarial example generation. The Single Pixel Attack perturbs one pixel at a time based on the model‘s output scores. The Square Attack and HopSkipJump Attack are query-efficient score-based attacks that can fool black-box models.
Decision-based Methods
Decision-based attacks generate adversarial examples based only on the final decision (class label) of the model, without access to scores or gradients. The Boundary Attack starts from a large adversarial perturbation and then reduces the perturbation while staying adversarial. The Evolutionary Attack uses genetic algorithms to evolve adversarial examples.
Transfer-based Methods
Transfer-based attacks generate adversarial examples against a substitute model, which are then transferred to fool the target model. This enables black-box attacks on the target model. Ensemble attacks generate adversarial examples against an ensemble of substitute models to improve transferability.
Adversarial Attack Impact
The impact of adversarial attacks depends on the attacker‘s goals. The most common goals are:
-
Misclassification: Cause the model to misclassify the adversarial example into any class different from the original.
-
Targeted Misclassification: Cause the model to misclassify the adversarial example into a specific target class chosen by the attacker.
-
Source/Target Misclassification: Cause the model to misclassify adversarial examples from one specific source class into a specific target class.
Adversarial attacks can have serious consequences when machine learning models are deployed in the real-world. For example:
-
An adversarial sticker on a stop sign could cause an self-driving car to misclassify it and fail to stop, leading to accidents.
-
Adversarial perturbations to medical scans could fool a model into missing a disease diagnosis, delaying treatment.
-
An adversary could evade a spam email filter or malware detector by generating adversarial spam/malware.
-
In a model-based authentication system, an adversary could impersonate an authorized user via adversarial biometrics.
-
Private data used to train a model could be revealed through model inversion and membership inference attacks.
It is therefore critical to be aware of adversarial attack risks and employ defenses to machine learning models, especially in security-sensitive applications. Even if adversarial attacks do not always translate perfectly to the physical world, they reveal concerning brittleness in our models.
Defenses Against Adversarial Attacks
Defending machine learning models against adversarial attacks is an active area of research. While there is no perfect defense yet, many methods have been proposed that can make models more robust:
Adversarial Training
Adversarial training involves augmenting the training data with adversarial examples and training the model to classify them correctly. This can make the model more robust by learning to resist adversarial perturbations. Ensemble adversarial training uses adversarial examples from multiple models to further improve robustness.
Defensive Distillation
Defensive distillation trains the model to be uncertain about its predictions by training it to predict the soft labels produced by another model. This makes it harder for attackers to find confident adversarial examples. However, distillation can be broken by certain attacks like C&W.
Gradient Masking/Obfuscation
Gradient masking aims to hide the model‘s gradients from an attacker, making it difficult to perform gradient-based attacks. Techniques include adding noise to gradients, ensemble methods, and vanishing/exploding gradients. However, gradient masking is often just "security through obscurity" and can give a false sense of security.
Input Transformation
Input transformation defenses preprocess the input before feeding it to the model in order to remove adversarial perturbations. Transformations can include quantization, smoothing, denoising, and JPEG compression. However, attackers can adapt to these transformations in some cases.
Randomized Smoothing
Randomized smoothing creates a smoothed classifier by adding random noise to the inputs and averaging the model‘s predictions. This can provably defend against adversarial perturbations within a certain size. However, randomized smoothing can degrade accuracy on clean examples and is computationally expensive.
Reject on Negative Impact
These defenses aim to detect and reject adversarial examples by measuring their negative impact on the model‘s performance. For example, by measuring how much an input decreases the model‘s confidence or activations. However, these methods often significantly reduce accuracy on benign examples.
Ensembles and Moving Target Defense
Ensemble defenses combine multiple diverse models to improve robustness, since an adversarial example for one model is unlikely to transfer to all models in the ensemble. Moving target defenses continuously change the model, making it harder for attackers to generate adversarial examples. However, these defenses are often expensive in terms of computation and memory.
Challenges and Future Work
While progress has been made in developing adversarial attack defenses, there are still many open challenges:
-
Most defenses are still vulnerable to adaptive attackers who are aware of the defense and can modify their attack accordingly. We need defenses that are truly robust.
-
Scaling adversarial defenses to complex real-world datasets and models is challenging. Many defenses have only been tested on simple datasets like MNIST and CIFAR-10.
-
There is often a trade-off between robustness and accuracy. Defenses that make a model more robust to adversarial examples often decrease its accuracy on benign examples. Achieving robustness without sacrificing accuracy is an important goal.
-
Reasoning about and proving robustness guarantees is hard. Most defenses are evaluated empirically, but we need stronger theories and proofs of when a model is robust.
-
The transferability of adversarial examples between different models is not well understood. We need to know when we can expect an attack to transfer to develop better defenses.
Future research directions to address these challenges include:
-
Developing new defense methods that can provide theoretical robustness guarantees.
-
Studying the relationship between robustness and other properties like interpretability, fairness, privacy, and generalization.
-
Designing models that are inherently more robust, rather than relying on defenses. For example, using robust architectures or training objectives.
-
Investigating the role of learning algorithms and data distributions in adversarial vulnerabilities. Can we collect datasets and design learning algorithms that result in more robust models?
-
Exploring the implications of adversarial examples for the security and safety of deployed machine learning systems, and developing best practices for defense-in-depth.
Conclusion
Adversarial attacks are a serious threat to machine learning systems that we must address as a community. By understanding the types of attacks, popular attack methods, and the impact of adversarial examples, we can develop more robust defenses and best practices. While there is no perfect defense yet, research in this area is rapidly progressing.
As machine learning is increasingly deployed in the real world, reasoning about the security and robustness of our models is more critical than ever. Every practitioner working with machine learning should be aware of adversarial attacks and think carefully about the risks and defenses relevant to their application. By working together to address this challenge, we can unlock the positive potential of machine learning while mitigating the risks.