Security and Robustness
Adversarial examples, data poisoning, backdoors and prompt injection.
A taxonomy of attacks
| Stage | Attack | Goal |
|---|---|---|
| Training | Poisoning, backdoors | Changing the model's behaviour |
| Inference | Adversarial examples | Fooling the decision |
| Inference | Model extraction | Copying the model through queries |
| Inference | Membership inference | Violating privacy |
| Language models | Direct and indirect injection | Bypassing instructions and leaking data |
Example: FGSM
$$x_{adv} = x + \epsilon \cdot \mathrm{sign}\big(\nabla_x \mathcal{L}(f(x), y)\big)$$
import torch
def fgsm(model, x, y, eps=2/255):
x = x.clone().requires_grad_(True)
loss = torch.nn.functional.cross_entropy(model(x), y)
loss.backward()
return (x + eps * x.grad.sign()).clamp(0, 1).detach()Prompt injection
- Direct: the user writes “Ignore the previous instructions…”.
- Indirect: instructions hidden in a web page or document that the agent reads.
- Defences: separating instructions from data as far as possible, restricting tool permissions, human confirmation of sensitive actions, and monitoring outputs. No complete solution is known so far.
Natural robustness
A change in lighting, device or dialect is not an attack, but it reveals a similar fragility. Evaluate the model on out-of-distribution data.
Defensive practices
- Verifying data sources and the supply chain, including pretrained models.
- Red teaming before and after deployment.
- The principle of least privilege.
- An incident response plan.
Lesson terms
- Red teaming
- An organized attempt to discover a system's weaknesses by simulating the behaviour of attackers or misuse.
- Adversarial example
- An input altered by a small change, often imperceptible to humans, that makes the model err confidently.
- Data poisoning
- Inserting malicious examples into the training data to influence the model's behaviour.
Abstract
AI systems are vulnerable to specific attacks. Adversarial examples are small changes to the inputs that fool the model. Data poisoning plants malicious examples in the training data, and backdoors make the model behave in a specific way when a certain pattern appears. In language models, prompt injection changes the system's behaviour through text in the inputs or the retrieved content. Robustness also includes performance under natural changes in the data. Defences include adversarial training, verifying data sources, restricting permissions, and red teaming.
Review questions
-
What is the idea of the FGSM attack?
Moving the input a small step in the direction of the sign of the loss gradient with respect to the input, to increase the loss.
-
Why is indirect prompt injection dangerous for agents?
Because the agent reads external content that may contain malicious instructions, and then carries out actions with its permissions.
Sources and references
Complete the lesson
You have completed all the lessons in the track! You can now request the track completion certificate.
Request the certificate