0
0
Prompt Engineering / GenAIml~10 mins

Red teaming and adversarial testing in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an adversarial example by adding small noise to the input.

Prompt Engineering / GenAI
adversarial_input = original_input + [1]
Drag options to blanks, or click blank then click option'
Alabels
Bnoise
Cmodel
Dloss
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'labels' instead of noise to modify the input.
Adding the model or loss instead of noise.
2fill in blank
medium

Complete the code to calculate the loss used for adversarial training.

Prompt Engineering / GenAI
loss = loss_function([1], predictions)
Drag options to blanks, or click blank then click option'
Aoriginal_labels
Badversarial_labels
Cadversarial_input
Dmodel_output
Attempts:
3 left
💡 Hint
Common Mistakes
Using adversarial input or model output instead of labels.
Confusing inputs with labels.
3fill in blank
hard

Fix the error in the code to generate adversarial noise using gradient sign method.

Prompt Engineering / GenAI
noise = epsilon * [1](loss, input, retain_graph=True)
Drag options to blanks, or click blank then click option'
Abackward
Bzero_grad
Cdetach
Dgrad
Attempts:
3 left
💡 Hint
Common Mistakes
Using backward() instead of accessing the gradient.
Calling zero_grad() or detach() incorrectly.
4fill in blank
hard

Fill both blanks to create a dictionary of adversarial examples filtered by confidence score.

Prompt Engineering / GenAI
adv_examples = {input: output for input, output in dataset.items() if output [1] threshold and confidence_score(input) [2] 0.8}
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for output filtering.
Using '<' instead of '>=' for confidence filtering.
5fill in blank
hard

Fill all three blanks to implement adversarial training step updating model parameters.

Prompt Engineering / GenAI
optimizer.[1]()
loss = loss_function(model([2]), labels)
loss.[3]()
Drag options to blanks, or click blank then click option'
Azero_grad
Badversarial_input
Cbackward
Doriginal_input
Attempts:
3 left
💡 Hint
Common Mistakes
Not clearing gradients before backward pass.
Using original input instead of adversarial input.
Calling backward on loss incorrectly.