code: def test_top_k_categorical_accuracy_works_for_sequences(self):
      accuracy = CategoricalAccuracy(top_k=2)
      predictions = torch.Tensor(
          [
              [
                  [0.35, 0.25, 0.1, 0.1, 0.2],
                  [0.1, 0.6, 0.1, 0.2, 0.0],
                  [0.1, 0.6, 0.1, 0.2, 0.0],
              ],
              [
                  [0.35, 0.25, 0.1, 0.1, 0.2],
                  [0.1, 0.6, 0.1, 0.2, 0.0],
                  [0.1, 0.6, 0.1, 0.2, 0.0],
              ],
          ]
      )
      targets = torch.Tensor([[0, 3, 4], [0, 1, 4]])
      accuracy(predictions, targets)
      actual_accuracy = accuracy.get_metric(reset=True)
      numpy.testing.assert_almost_equal(actual_accuracy, 0.6666666)
  
      # Test the same thing but with a mask:
      mask = torch.Tensor([[0, 1, 1], [1, 0, 1]])
      accuracy(predictions, targets, mask)
      actual_accuracy = accuracy.get_metric(reset=True)
      numpy.testing.assert_almost_equal(actual_accuracy, 0.50)
  
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 5 for calling the CategoricalAccuracyTest obj's underlying member method code with example usage: obj.test_top_k_categorical_accuracy_works_for_sequences() without return types