code: def compute_perplexity(result):
      """Computes and add the perplexity to the LogReport
  
      :param dict result: The current observations
      """
      # Routine to rewrite the result dictionary of LogReport to add perplexity values
      result["perplexity"] = np.exp(
          result["main/loss"] / result["main/count"]
      )
      if "validation/main/loss" in result:
          result["val_perplexity"] = np.exp(
              result["validation/main/loss"]
          )
  
imports: import logging
  import os
  import random
  import chainer
  import h5py
  import numpy
  from chainer.training import extension
  from tqdm import tqdm
label_desc: Use image node_id 4 for calling a global function with example usage: compute_perplexity(result) without return types