code: def test_tie_break_categorical_accuracy(self, device: str):
      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],
          ],
          device=device,
      )
      # Test without mask:
      targets = torch.tensor([2, 1, 4], device=device)
      accuracy(predictions, targets)
      assert accuracy.get_metric(reset=True) == (0.25 + 1 + 0.5) / 3.0
  
      # # # Test with mask
      mask = torch.tensor([True, False, True], device=device)
      targets = torch.tensor([2, 1, 4], device=device)
      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],
              ],
          ],
          device=device,
      )
      targets = torch.tensor(
          [[0, 1, 3], [0, 3, 4]],
          device=device,  # 0.25 + 1 + 0.5  # 0.25 + 0 + 0.5 = 2.5
      )
      accuracy(predictions, targets)
      actual_accuracy = accuracy.get_metric(reset=True)
      assert_allclose(actual_accuracy, 2.5 / 6.0)
  
imports: import pytest
  import torch
  from torch.testing import assert_allclose
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase, multi_device, global_distributed_metric, run_distributed_test
  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(device) without return types