All problems
IOB Consistency Check
Problem
Return True when a tag sequence is valid IOB2: every I-label must follow a B-label or I-label with the same entity type, B- and I- labels are the only allowed entity tags, and O is always allowed.
An empty sequence is valid.
Hint
Track the previous tag and compare entity types on every I- tag.
Test cases
case 1
in: [["B-PER","I-PER","O"]]
expected: true
case 2
in: [["I-PER","O"]]
expected: false
case 3
in: [["B-PER","I-LOC"]]
expected: false
case 4
in: [["O","O"]]
expected: true
case 5
in: [[]]
expected: true
Starter codePython
def iob_consistency_check(tags):
# Your code here
pass5 test cases · run your code against them in the editor