code: def test_iob1_tags_to_spans_extracts_correct_spans(self):
      tag_sequence = [
          "I-ARG2",
          "B-ARG1",
          "I-ARG1",
          "O",
          "B-ARG2",
          "I-ARG2",
          "B-ARG1",
          "B-ARG2",
      ]
      spans = span_utils.iob1_tags_to_spans(tag_sequence)
      assert set(spans) == set(
          [
              ("ARG2", (0, 0)),
              ("ARG1", (1, 2)),
              ("ARG2", (4, 5)),
              ("ARG1", (6, 6)),
              ("ARG2", (7, 7)),
          ]
      )
  
      # Check that it raises when we use U- tags for single tokens.
      tag_sequence = [
          "O",
          "B-ARG1",
          "I-ARG1",
          "O",
          "B-ARG2",
          "I-ARG2",
          "U-ARG1",
          "U-ARG2",
      ]
      with self.assertRaises(span_utils.InvalidTagSequence):
          spans = span_utils.iob1_tags_to_spans(tag_sequence)
  
      # Check that invalid IOB1 sequences are also handled as spans.
      tag_sequence = [
          "O",
          "B-ARG1",
          "I-ARG1",
          "O",
          "I-ARG1",
          "B-ARG2",
          "I-ARG2",
          "B-ARG1",
          "I-ARG2",
          "I-ARG2",
      ]
      spans = span_utils.iob1_tags_to_spans(tag_sequence)
      assert set(spans) == set(
          [
              ("ARG1", (1, 2)),
              ("ARG1", (4, 4)),
              ("ARG2", (5, 6)),
              ("ARG1", (7, 7)),
              ("ARG2", (8, 9)),
          ]
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/data/dataset_readers/dataset_utils/span_utils_test.py
imports: from __future__ import with_statement
  from __future__ import absolute_import
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data.dataset_readers.dataset_utils import span_utils
  from allennlp.data.tokenizers.word_tokenizer import SpacyWordSplitter
  from allennlp.data.tokenizers.token import Token
label_desc: Use image node_id 5 for calling the SpanUtilsTest obj's underlying member method code with example usage: obj.test_iob1_tags_to_spans_extracts_correct_spans() without return types