Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-109

Label Smoothing

Problem

Build smoothed one-hot targets: the true class gets 1 - epsilon and every other class gets epsilon / (num_classes - 1).

Return the list of rows; empty input returns [].

Hint

Redistribute epsilon mass equally to the non-target classes.

Test cases

case 1
in: [[0,2],3,0.3]
expected: [[0.7,0.15,0.15],[0.15,0.15,0.7]]
case 2
in: [[1],2,0.2]
expected: [[0.2,0.8]]
case 3
in: [[0],1,0.1]
expected: [[0.9]]
case 4
in: [[],3,0.1]
expected: []
Starter codePython
def label_smoothing(y_true, num_classes, epsilon):
    # Your code here
    pass

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