def METHOD_NAME(self):
    with self.cached_session():
        # Test correctness if the shape of y_true is (num_samples, 1)
        y_pred = backend.variable(
            np.array([[0.3, 0.2, 0.1], [0.1, 0.2, 0.7]])
        )
        y_true = backend.variable(np.array([[1], [0]]))
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=3)
        )
        self.assertEqual(np.mean(result), 1)
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=2)
        )
        self.assertEqual(np.mean(result), 0.5)
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=1)
        )
        self.assertEqual(np.mean(result), 0.0)
        # Test correctness if the shape of y_true is (num_samples,)
        y_pred = backend.variable(
            np.array([[0.3, 0.2, 0.1], [0.1, 0.2, 0.7]])
        )
        y_true = backend.variable(np.array([1, 0]))
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=3)
        )
        self.assertEqual(np.mean(result), 1)
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=2)
        )
        self.assertEqual(np.mean(result), 0.5)
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=1)
        )
        self.assertEqual(np.mean(result), 0.0)
        # Test correctness if the shape of y_true is (batch_size,
        # seq_length) and y_pred is (batch_size, seq_length, num_classes)
        y_pred = backend.variable(
            np.array(
                [
                    [[0.3, 0.2, 0.1], [0.1, 0.2, 0.7], [0.1, 0.2, 0.7]],
                    [[0.3, 0.2, 0.1], [0.1, 0.2, 0.7], [0.3, 0.2, 0.1]],
                ]
            )
        )
        y_true = backend.variable(np.array([[1, 0, 0], [1, 0, 1]]))
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=3)
        )
        self.assertEqual(np.mean(result), 1)
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=2)
        )
        self.assertEqual(np.mean(result), 0.5)
        result = backend.eval(
            metrics.sparse_top_k_categorical_accuracy(y_true, y_pred, k=1)
        )
        self.assertEqual(np.mean(result), 0.0)