All problems
Answer Span Constraint Count
Problem
Count the QA answer spans that satisfy a maximum length and a score threshold. start_logits and end_logits are per-position scores, and a span [i, j] is valid when j is at least i, the inclusive length j - i + 1 is at most max_length, and start_logits[i] + end_logits[j] is strictly greater than threshold.
Return the number of valid spans, or 0 when max_length is not positive.
Hint
Enumerate i and j with j from i to i + max_length - 1, then apply the strict threshold test.
Test cases
case 1
in: [[0.5,0.1],[0.4,0.2],2,0.5]
expected: 2
case 2
in: [[0.5,0.1],[0.4,0.2],2,0]
expected: 3
case 3
in: [[0.5,0.1],[0.4,0.2],1,0]
expected: 2
case 4
in: [[0.5,0.1],[0.4,0.2],2,1]
expected: 0
case 5
in: [[],[],2,0]
expected: 0
Starter codePython
def answer_span_constraint_count(start_logits, end_logits, max_length, threshold):
# Your code here
pass5 test cases · run your code against them in the editor