Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-107

BIO Tagging Decode

Problem

Decode a BIO tag sequence into entity spans. Return a list of [start, end, label] triples where end is exclusive.

A B- tag starts a new entity, an I- tag continues the current entity when the label matches and otherwise starts a new one, and O closes the current entity.

Hint

Keep the current entity start and label, flushing at every O or label change.

Test cases

case 1
in: [["B-PER","I-PER","O","B-LOC"]]
expected: [[0,2,"PER"],[3,4,"LOC"]]
case 2
in: [["I-PER","O"]]
expected: [[0,1,"PER"]]
case 3
in: [["O","O"]]
expected: []
case 4
in: [[]]
expected: []
case 5
in: [["B-PER","I-LOC","I-LOC"]]
expected: [[0,1,"PER"],[1,3,"LOC"]]
Starter codePython
def bio_decode(tags):
    # Your code here
    pass

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