code: def test_span_f1_accepts_tags_to_spans_function_argument(
      self, device: str
  ):
      def mock_tags_to_spans_function(
          tag_sequence, classes_to_ignore=None
      ):
          return [("mock", (42, 42))]
  
      # Should be ignore.
      bio_tags = ["B-ARG1", "O", "B-C-ARG1", "B-V", "B-ARGM-ADJ", "O"]
      gold_indices = [
          self.vocab.get_token_index(x, "tags") for x in bio_tags
      ]
      gold_tensor = torch.tensor([gold_indices], device=device)
      prediction_tensor = torch.rand(
          [1, 6, self.vocab.get_vocab_size("tags")], device=device
      )
  
      metric = SpanBasedF1Measure(
          self.vocab,
          "tags",
          label_encoding=None,
          tags_to_spans_function=mock_tags_to_spans_function,
      )
  
      metric(prediction_tensor, gold_tensor)
      metric_dict = metric.get_metric()
  
      assert_allclose(metric_dict["recall-overall"], 1.0)
      assert_allclose(metric_dict["precision-overall"], 1.0)
      assert_allclose(metric_dict["f1-measure-overall"], 1.0)
  
      with pytest.raises(ConfigurationError):
          SpanBasedF1Measure(self.vocab, label_encoding="INVALID")
      with pytest.raises(ConfigurationError):
          SpanBasedF1Measure(
              self.vocab,
              tags_to_spans_function=mock_tags_to_spans_function,
          )
      with pytest.raises(ConfigurationError):
          SpanBasedF1Measure(
              self.vocab,
              label_encoding=None,
              tags_to_spans_function=None,
          )
  
file_path: allennlp/tests/training/metrics/span_based_f1_measure_test.py
imports: import torch
  from torch.testing import assert_allclose
  import pytest
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.params import Params
  from allennlp.common.testing import AllenNlpTestCase, multi_device
  from allennlp.data import Vocabulary
  from allennlp.training.metrics import SpanBasedF1Measure, Metric
label_desc: Use image node_id 6 for calling the SpanBasedF1Test obj's underlying member method code with example usage: obj.test_span_f1_accepts_tags_to_spans_function_argument(device) and returns: list