code: def test_perplexity():
      pred = mx.np.array([[0.8, 0.2], [0.2, 0.8], [0, 1.0]])
      label = mx.np.array([0, 1, 1])
      p = pred.asnumpy()[
          np.arange(label.size), label.asnumpy().astype("int32")
      ]
      perplexity_expected = np.exp(-np.log(p).sum() / label.size)
      metric = mx.gluon.metric.create("perplexity", axis=-1)
      metric.update([label], [pred])
      _, perplexity = metric.get()
      np.testing.assert_almost_equal(perplexity, perplexity_expected)
  
imports: import mxnet
  from mxnet.test_utils import use_np
  import numpy
  import scipy
  from scipy.stats import pearsonr
  import json
  import math
  from common import xfail_when_nonstandard_decimal_separator
  from copy import deepcopy
label_desc: Use image node_id 11 for calling a global function with example usage: test_perplexity() without return types