0
0
Prompt Engineering / GenAIml~10 mins

Generative vs discriminative models in Prompt Engineering / GenAI - Interactive Practice

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

Complete the code to define a generative model that learns the joint probability of data and labels.

Prompt Engineering / GenAI
model = GenerativeModel(p_x_y=[1])
Drag options to blanks, or click blank then click option'
AP(x, y)
BP(x|y)
CP(y|x)
DP(y)
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing conditional probability instead of joint probability.
2fill in blank
medium

Complete the code to define a discriminative model that learns the conditional probability of labels given data.

Prompt Engineering / GenAI
model = DiscriminativeModel(p_y_given_x=[1])
Drag options to blanks, or click blank then click option'
AP(x, y)
BP(x)
CP(x|y)
DP(y|x)
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing joint probability with conditional probability.
3fill in blank
hard

Fix the error in the code to train a discriminative model using maximum likelihood estimation.

Prompt Engineering / GenAI
loss = -sum(log([1](y|x)) for x, y in dataset)
Drag options to blanks, or click blank then click option'
AP(x|y)
BP(x, y)
CP(y|x)
DP(y)
Attempts:
3 left
💡 Hint
Common Mistakes
Using joint probability instead of conditional probability in loss.
4fill in blank
hard

Fill both blanks to complete the code that generates new data samples from a generative model.

Prompt Engineering / GenAI
samples = model.sample([1])
print('Generated samples:', [2])
Drag options to blanks, or click blank then click option'
Anum_samples
Bsamples
Cdata
Dlabels
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for sample count or output.
5fill in blank
hard

Fill all three blanks to complete the code that compares generative and discriminative models on accuracy.

Prompt Engineering / GenAI
gen_model = GenerativeModel()
disc_model = DiscriminativeModel()

accuracy_gen = gen_model.evaluate_accuracy([1])
accuracy_disc = disc_model.evaluate_accuracy([2])

print('Generative accuracy:', accuracy_gen)
print('Discriminative accuracy:', accuracy_disc)

better_model = [3] if accuracy_gen > accuracy_disc else disc_model
Drag options to blanks, or click blank then click option'
Atest_data
Cgen_model
Ddisc_model
Attempts:
3 left
💡 Hint
Common Mistakes
Using different data for evaluation or wrong model variable in comparison.