0
0
Prompt Engineering / GenAIml~10 mins

Re-ranking retrieved results 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 sort the retrieved results by their scores in descending order.

Prompt Engineering / GenAI
sorted_results = sorted(results, key=lambda x: x['score'], reverse=[1])
Drag options to blanks, or click blank then click option'
A0
BFalse
CTrue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using reverse=False which sorts ascending instead of descending.
Using None or 0 which are invalid for reverse parameter.
2fill in blank
medium

Complete the code to select the top 5 results after re-ranking.

Prompt Engineering / GenAI
top_results = sorted_results[:[1]]
Drag options to blanks, or click blank then click option'
A3
B5
C10
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 or 10 which selects wrong number of results.
Using 0 which results in an empty list.
3fill in blank
hard

Fix the error in the code to compute new scores by multiplying original scores by a re-ranker score.

Prompt Engineering / GenAI
for item in results:
    item['new_score'] = item['score'] * item[[1]]
Drag options to blanks, or click blank then click option'
A'rank_score'
B'score'
C'new_score'
D're_rank_score'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'score' which multiplies the score by itself.
Using 'new_score' which is not yet defined.
Using 'rank_score' which is not a valid key.
4fill in blank
hard

Fill both blanks to create a dictionary of item IDs mapped to their new scores, filtering only items with new_score above 0.5.

Prompt Engineering / GenAI
filtered_scores = {item['id']: item[[1]] for item in results if item[[2]] > 0.5}
Drag options to blanks, or click blank then click option'
A'new_score'
B'score'
D're_rank_score'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for mapping and filtering causing errors.
Using 'score' or 're_rank_score' which are not the updated scores.
5fill in blank
hard

Fill all three blanks to sort the filtered scores dictionary by score descending and get a list of top 3 item IDs.

Prompt Engineering / GenAI
top_ids = [k for k, v in sorted(filtered_scores.items(), key=lambda item: item[[1]], reverse=[2])[:[3]]]
Drag options to blanks, or click blank then click option'
A1
BTrue
C3
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by index 0 which is the key, not the score.
Using reverse=False which sorts ascending.
Slicing with wrong number like 0 or 1.