code: def test_tie_break_categorical_accuracy(self):
      accuracy = CategoricalAccuracy(tie_break=True)
      predictions = torch.Tensor(
          [
              [0.35, 0.25, 0.35, 0.35, 0.35],
              [0.1, 0.6, 0.1, 0.2, 0.2],
              [0.1, 0.0, 0.1, 0.2, 0.2],
          ]
      )
      # Test without mask:
      targets = torch.Tensor([2, 1, 4])
      accuracy(predictions, targets)
      assert accuracy.get_metric(reset=True) == (0.25 + 1 + 0.5) / 3.0
  
      # # # Test with mask
      mask = torch.Tensor([1, 0, 1])
      targets = torch.Tensor([2, 1, 4])
      accuracy(predictions, targets, mask)
      assert accuracy.get_metric(reset=True) == (0.25 + 0.5) / 2.0
  
      # # Test tie-break with sequence
      predictions = torch.Tensor(
          [
              [
                  [0.35, 0.25, 0.35, 0.35, 0.35],
                  [0.1, 0.6, 0.1, 0.2, 0.2],
                  [0.1, 0.0, 0.1, 0.2, 0.2],
              ],
              [
                  [0.35, 0.25, 0.35, 0.35, 0.35],
                  [0.1, 0.6, 0.1, 0.2, 0.2],
                  [0.1, 0.0, 0.1, 0.2, 0.2],
              ],
          ]
      )
      targets = torch.Tensor(
          [[0, 1, 3], [0, 3, 4]]  # 0.25 + 1 + 0.5
      )  # 0.25 + 0 + 0.5 = 2.5
      accuracy(predictions, targets)
      actual_accuracy = accuracy.get_metric(reset=True)
      numpy.testing.assert_almost_equal(actual_accuracy, 2.5 / 6.0)
  
imports: from __future__ import division
  from __future__ import with_statement
  from __future__ import absolute_import
  import torch
  import pytest
  import numpy
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.common.checks import ConfigurationError
  from allennlp.training.metrics import CategoricalAccuracy
label_desc: Use image node_id 7 for calling the CategoricalAccuracyTest obj's underlying member method code with example usage: obj.test_tie_break_categorical_accuracy() without return types