Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-281

IOB2 Illegal Transition Positions

Problem

Find every position where a tag sequence violates the IOB2 transition rule. An I-label is only legal when the previous tag is the B- or I-label of the same entity type, where the position before the first tag acts as O.

Return the sorted list of violating indices, and an empty list when the sequence is valid.

Hint

Only I- tags can be illegal; compare the label with the previous tag.

Test cases

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

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