code: def test_bmes_span_metrics_are_computed_correctly(self, device: str):
      # (bmes_tags) B:0, M:1, E:2, S:3.
      # [S, B, M, E, S]
      # [S, S, S, S, S]
      gold_indices = [[3, 0, 1, 2, 3], [3, 3, 3, 3, 3]]
      gold_tensor = torch.tensor(gold_indices, device=device)
  
      prediction_tensor = torch.rand([2, 5, 4], device=device)
      # [S, B, E, S, S]
      # TP: 2, FP: 2, FN: 1.
      prediction_tensor[0, 0, 3] = 1  # (True positive)
      prediction_tensor[0, 1, 0] = 1  # (False positive
      prediction_tensor[0, 2, 2] = 1  # *)
      prediction_tensor[0, 3, 3] = 1  # (False positive)
      prediction_tensor[0, 4, 3] = 1  # (True positive)
      # [B, E, S, B, E]
      # TP: 1, FP: 2, FN: 4.
      prediction_tensor[1, 0, 0] = 1  # (False positive
      prediction_tensor[1, 1, 2] = 1  # *)
      prediction_tensor[1, 2, 3] = 1  # (True positive)
      prediction_tensor[1, 3, 0] = 1  # (False positive
      prediction_tensor[1, 4, 2] = 1  # *)
  
      metric = SpanBasedF1Measure(
          self.vocab, "bmes_tags", label_encoding="BMES"
      )
      metric(prediction_tensor, gold_tensor)
  
      # TP: 3, FP: 4, FN: 5.
      metric_dict = metric.get_metric()
  
      assert_allclose(
          metric_dict["recall-overall"], 0.375, rtol=0.001, atol=1e-03
      )
      assert_allclose(
          metric_dict["precision-overall"],
          0.428,
          rtol=0.001,
          atol=1e-03,
      )
      assert_allclose(
          metric_dict["f1-measure-overall"], 0.4, rtol=0.001, atol=1e-03
      )
  
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 4 for calling the SpanBasedF1Test obj's underlying member method code with example usage: obj.test_bmes_span_metrics_are_computed_correctly(device) without return types