code: def test_span_metrics_are_computed_correcly_with_prediction_map(self):
      # In this example, datapoint1 only has access to ARG1 and V labels,
      # whereas datapoint2 only has access to ARG2 and V labels.
  
      # gold_labels = [["O", "B-ARG1", "I-ARG1", "O", "B-V", "O"],
      #               ["B-ARG2", "I-ARG2", "O", "B-V", "I-V", "O"]]
      gold_indices = [[0, 1, 2, 0, 3, 0], [1, 2, 0, 3, 4, 0]]
      prediction_map_indices = [[0, 1, 2, 5, 6], [0, 3, 4, 5, 6]]
  
      gold_tensor = torch.Tensor(gold_indices)
      prediction_map_tensor = torch.Tensor(prediction_map_indices)
  
      prediction_tensor = torch.rand([2, 6, 5])
      prediction_tensor[0, 0, 0] = 1
      prediction_tensor[0, 1, 1] = 1  # (True Positive - ARG1
      prediction_tensor[0, 2, 2] = 1  # *)
      prediction_tensor[0, 3, 0] = 1
      prediction_tensor[0, 4, 3] = 1  # (True Positive - V)
      prediction_tensor[0, 5, 1] = 1  # (False Positive - ARG1)
      prediction_tensor[1, 0, 0] = 1  # (False Negative - ARG2
      prediction_tensor[1, 1, 0] = 1  # *)
      prediction_tensor[1, 2, 0] = 1
      prediction_tensor[1, 3, 3] = 1  # (True Positive - V
      prediction_tensor[1, 4, 4] = 1  # *)
      prediction_tensor[1, 5, 1] = 1  # (False Positive - ARG2)
  
      metric = SpanBasedF1Measure(self.vocab, "tags")
      metric(
          prediction_tensor,
          gold_tensor,
          prediction_map=prediction_map_tensor,
      )
  
      assert metric._true_positives["ARG1"] == 1
      assert metric._true_positives["ARG2"] == 0
      assert metric._true_positives["V"] == 2
      assert "O" not in list(metric._true_positives.keys())
      assert metric._false_negatives["ARG1"] == 0
      assert metric._false_negatives["ARG2"] == 1
      assert metric._false_negatives["V"] == 0
      assert "O" not in list(metric._false_negatives.keys())
      assert metric._false_positives["ARG1"] == 1
      assert metric._false_positives["ARG2"] == 1
      assert metric._false_positives["V"] == 0
      assert "O" not in list(metric._false_positives.keys())
  
      # Check things are accumulating correctly.
      metric(
          prediction_tensor,
          gold_tensor,
          prediction_map=prediction_map_tensor,
      )
      assert metric._true_positives["ARG1"] == 2
      assert metric._true_positives["ARG2"] == 0
      assert metric._true_positives["V"] == 4
      assert "O" not in list(metric._true_positives.keys())
      assert metric._false_negatives["ARG1"] == 0
      assert metric._false_negatives["ARG2"] == 2
      assert metric._false_negatives["V"] == 0
      assert "O" not in list(metric._false_negatives.keys())
      assert metric._false_positives["ARG1"] == 2
      assert metric._false_positives["ARG2"] == 2
      assert metric._false_positives["V"] == 0
      assert "O" not in list(metric._false_positives.keys())
  
      metric_dict = metric.get_metric()
  
      numpy.testing.assert_almost_equal(metric_dict["recall-ARG2"], 0.0)
      numpy.testing.assert_almost_equal(
          metric_dict["precision-ARG2"], 0.0
      )
      numpy.testing.assert_almost_equal(
          metric_dict["f1-measure-ARG2"], 0.0
      )
      numpy.testing.assert_almost_equal(metric_dict["recall-ARG1"], 1.0)
      numpy.testing.assert_almost_equal(
          metric_dict["precision-ARG1"], 0.5
      )
      numpy.testing.assert_almost_equal(
          metric_dict["f1-measure-ARG1"], 0.666666666
      )
      numpy.testing.assert_almost_equal(metric_dict["recall-V"], 1.0)
      numpy.testing.assert_almost_equal(metric_dict["precision-V"], 1.0)
      numpy.testing.assert_almost_equal(
          metric_dict["f1-measure-V"], 1.0
      )
      numpy.testing.assert_almost_equal(
          metric_dict["recall-overall"], 0.75
      )
      numpy.testing.assert_almost_equal(
          metric_dict["precision-overall"], 0.6
      )
      numpy.testing.assert_almost_equal(
          metric_dict["f1-measure-overall"], 0.666666666
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/training/metrics/span_based_f1_measure_test.py
imports: from __future__ import division
  from __future__ import with_statement
  from __future__ import absolute_import
  import os
  import subprocess
  import torch
  import numpy
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data import Vocabulary
  from allennlp.training.metrics import SpanBasedF1Measure, Metric
  from allennlp.models.semantic_role_labeler import write_to_conll_eval_file
  from allennlp.common.params import Params
  from io import open
label_desc: Use image node_id 2 for calling the SpanBasedF1Test obj's underlying member method code with example usage: obj.test_span_metrics_are_computed_correcly_with_prediction_map() without return types