Complete the code to sort the retrieved results by their scores in descending order.
sorted_results = sorted(results, key=lambda x: x['score'], reverse=[1])
Setting reverse=True sorts the list from highest to lowest score, which is needed for re-ranking.
Complete the code to select the top 5 results after re-ranking.
top_results = sorted_results[:[1]]We want the top 5 results, so slicing up to index 5 selects the first five items.
Fix the error in the code to compute new scores by multiplying original scores by a re-ranker score.
for item in results: item['new_score'] = item['score'] * item[[1]]
The re-ranker score is stored under the key 're_rank_score', so we multiply by that.
Fill both blanks to create a dictionary of item IDs mapped to their new scores, filtering only items with new_score above 0.5.
filtered_scores = {item['id']: item[[1]] for item in results if item[[2]] > 0.5}We want to map IDs to new_score and filter by new_score greater than 0.5.
Fill all three blanks to sort the filtered scores dictionary by score descending and get a list of top 3 item IDs.
top_ids = [k for k, v in sorted(filtered_scores.items(), key=lambda item: item[[1]], reverse=[2])[:[3]]]
We sort by the value at index 1 (the score), descending (reverse=True), and take the top 3 IDs.