All problems
Span to BIO Tags
Problem
Convert entity spans back to BIO tags for a sequence of n tokens. Each span is [start, end, label] with an exclusive end.
Emit 'B-label' at start, 'I-label' for the remaining positions up to end, and 'O' everywhere else.
Hint
Slice the span against n so an over-long end cannot overflow the tag list.
Test cases
case 1
in: [4,[[0,2,"PER"],[3,4,"LOC"]]]
expected: ["B-PER","I-PER","O","B-LOC"]
case 2
in: [2,[]]
expected: ["O","O"]
case 3
in: [0,[]]
expected: []
case 4
in: [3,[[1,3,"MISC"]]]
expected: ["O","B-MISC","I-MISC"]
Starter codePython
def span_to_bio(n, spans):
# Your code here
pass4 test cases · run your code against them in the editor