Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-172

Best-of-N Selection

Problem

Score best-of-N candidates. Return [best_index, best_probability], where best_index is the argmax of the scores (ties to the smaller index) and best_probability is the softmax probability of that index under softmax(scores / temperature), computed stably.

The signature is best_of_n(scores, temperature).

Hint

Low temperature concentrates the probability on the top candidate.

Test cases

case 1
in: [[1,2,3],1]
expected: [2,0.6652409558]
case 2
in: [[1,1],1]
expected: [0,0.5]
case 3
in: [[1,2],0.5]
expected: [1,0.880797078]
case 4
in: [[5,4,3],10]
expected: [0,0.3671654011]
Starter codePython
import math
def best_of_n(scores, temperature):
    # Your code here
    pass

4 test cases · run your code against them in the editor