0
0
Prompt Engineering / GenAIml~10 mins

Bias in generative models 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 load a pre-trained generative model.

Prompt Engineering / GenAI
model = load_model('[1]')
Drag options to blanks, or click blank then click option'
Abert-base-uncased
Bgpt2
Cresnet50
Dvgg16
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing image models like resnet50 or vgg16 which are not generative text models.
Selecting bert-base-uncased which is mainly for understanding text, not generation.
2fill in blank
medium

Complete the code to generate text from the model.

Prompt Engineering / GenAI
output = model.generate(input_ids, max_length=[1])
Drag options to blanks, or click blank then click option'
A10
B0
C50
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or negative numbers which prevent generation.
Choosing too small a number like 10 which limits output length.
3fill in blank
hard

Fix the error in the code to detect bias in generated text.

Prompt Engineering / GenAI
if '[1]' in generated_text.lower():
    print('Potential bias detected')
Drag options to blanks, or click blank then click option'
Aoffensive
Bgendered words
Cbias
Dstereotypes
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for generic words like 'bias' which may not appear literally.
Using 'gendered words' which is too specific without context.
4fill in blank
hard

Fill both blanks to filter out biased words from generated output.

Prompt Engineering / GenAI
filtered_output = [word for word in generated_text.split() if word.lower() [1] biased_words and word.lower() [2] biased_words]
Drag options to blanks, or click blank then click option'
Anot in
Bin
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'in' which would keep biased words instead of filtering them out.
Using '==' which would only keep biased words.
5fill in blank
hard

Fill all three blanks to calculate bias score from generated text.

Prompt Engineering / GenAI
bias_score = sum(1 for word in generated_text.split() if word.lower() [1] biased_words) / [2](generated_text.split())
if bias_score > [3]:
    print('High bias detected')
Drag options to blanks, or click blank then click option'
Ain
Blen
C0.1
Dnot in
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' which counts non-biased words instead.
Using a threshold too high or too low for bias detection.