PIXELBANKv9.1.0
Menu

Convert entity annotations to BIO (Beginning-Inside-Outside) tag sequences.

In NER, each token gets a tag:

  • B-TYPE: Beginning of an entity of type TYPE
  • I-TYPE: Inside (continuation of) an entity of type TYPE
  • O: Outside any entity

Input format:

  • Line 1: The tokens (space-separated)
  • Line 2: Number of entity annotations E
  • Lines 3 to E+2: start_index end_index entity_type (space-separated)

start_index and end_index are inclusive token indices.

Output: A list of BIO tags, one per token.

Example:

Input:
John Smith lives in New York City
2
0 1 PER
4 6 LOC
Output:
['B-PER', 'I-PER', 'O', 'O', 'B-LOC', 'I-LOC', 'I-LOC']
Reasoning:

Tokens: ["John", "Smith", "lives", "in", "New", "York", "City"]

Entity 1: indices 0-1, type PER

  • Index 0 "John" -> B-PER (beginning)
  • Index 1 "Smith" -> I-PER (inside)

Entity 2: indices 4-6, type LOC

  • Index 4 "New" -> B-LOC
  • Index 5 "York" -> I-LOC
  • Index 6 "City" -> I-LOC

All others: O

Constraints:

  • Indices are 0-based and inclusive
  • Entities do not overlap
  • Tag format: B-TYPE for first token, I-TYPE for remaining tokens of entity
  • All non-entity tokens get tag "O"
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.