Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-083

Mixup Loss from Logits

Problem

Mixup training loss for one example: lam * CE(logits, y_a) + (1 - lam) * CE(logits, y_b), using stable cross-entropy for each label.

The signature is mixup_loss(logits, y_a, y_b, lam).

Hint

The mixup coefficient blends the two one-hot cross-entropy terms.

Test cases

case 1
in: [[1,2,3],2,0,0.7]
expected: 1.0076059644
case 2
in: [[1,2,3],2,0,1]
expected: 0.4076059644
case 3
in: [[1,2,3],2,0,0]
expected: 2.4076059644
case 4
in: [[0,0],0,1,0.5]
expected: 0.6931471806
Starter codePython
import math
def mixup_loss(logits, y_a, y_b, lam):
    # Your code here
    pass

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