All problems
Grounded Answer Span
Problem
Locate answer_tokens inside doc_tokens as a contiguous subsequence. Return [start, end] inclusive indices of the first occurrence, or [-1, -1] when the answer is empty or absent.
Matching is exact and token-level.
Hint
Compare windows of the document with the full answer token list.
Test cases
case 1
in: [["the","cat","sat","down"],["cat","sat"]]
expected: [1,2]
case 2
in: [["a","b"],["z"]]
expected: [-1,-1]
case 3
in: [[],["a"]]
expected: [-1,-1]
case 4
in: [["a"],[]]
expected: [-1,-1]
case 5
in: [["x","a","b","a","b"],["a","b"]]
expected: [1,2]
Starter codePython
def grounded_answer_span(doc_tokens, answer_tokens):
# Your code here
pass5 test cases · run your code against them in the editor