code: def compute_perplexity(result):
      result["perplexity"] = np.exp(result["main/loss"])
      if "validation/main/loss" in result:
          result["val_perplexity"] = np.exp(
              result["validation/main/loss"]
          )
  
imports: from __future__ import division
  import argparse
  import sys
  import numpy
  import chainer
  import chainer.functions
  import chainer.links
  from chainer import training
  from chainer.training import extensions
  import chainerx
label_desc: Use image node_id 1 for calling a global function with example usage: compute_perplexity(result) without return types