Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-280

BIO Span Length Counts

Problem

Decode a BIO tag sequence and count spans by length. A B- tag starts a new entity, an I- tag continues the current entity when the label matches and otherwise starts a new entity, and O closes the current entity.

Return [number of single-token spans, number of multi-token spans].

Hint

Track the current span start and flush its length whenever the tag closes it.

Test cases

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

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