All problems
Contradiction Probability
Problem
Return the softmax probability of the contradiction class (index 1) over the NLI logits.
Use the max-subtraction trick for numerical stability. The logits must contain at least two entries.
Hint
Compute the full softmax first, then read the probability at index 1.
Test cases
case 1
in: [[2,1,0]]
expected: 0.24472847105479764
case 2
in: [[0,0,0]]
expected: 0.3333333333333333
case 3
in: [[0,5,0]]
expected: 0.986703291042268
case 4
in: [[1,1]]
expected: 0.5
Starter codePython
import math
def contradiction_probability(logits):
# Your code here
pass4 test cases · run your code against them in the editor