class_docstr: A class to wrap training code.
docstr: Computes the perplexity of a single sampled model on a minibatch of
  validation data.
code: def get_reward(self, dag, entropies, hidden, valid_idx=0):
      """Computes the perplexity of a single sampled model on a minibatch of
      validation data.
      """
      if not isinstance(entropies, np.ndarray):
          entropies = entropies.data.cpu().numpy()
  
      inputs, targets = self.get_batch(
          self.valid_data, valid_idx, self.max_length, volatile=True
      )
      valid_loss, hidden, _ = self.get_loss(
          inputs, targets, hidden, dag
      )
      valid_loss = utils.to_item(valid_loss.data)
  
      valid_ppl = math.exp(valid_loss)
  
      # TODO: we don't know reward_c
      if self.args.ppl_square:
          # TODO: but we do know reward_c=80 in the previous paper
          R = self.args.reward_c / valid_ppl**2
      else:
          R = self.args.reward_c / valid_ppl
  
      if self.args.entropy_mode == "reward":
          rewards = R + self.args.entropy_coeff * entropies
      elif self.args.entropy_mode == "regularizer":
          rewards = R * np.ones_like(entropies)
      else:
          raise NotImplementedError(
              f"Unkown entropy mode: {self.args.entropy_mode}"
          )
  
      return rewards, hidden
  
imports: import contextlib
  import glob
  import math
  import os
  import numpy
  import scipy.signal
  from tensorboard import TensorBoard
  import torch
  from torch import nn
  import torch.nn.parallel
  from torch.autograd import Variable
  import models
  import utils
label_desc: Use image node_id 6 for calling the Trainer obj's underlying member method code with example usage: obj.get_reward(dag, entropies, hidden, valid_idx) and returns: rewards,  hidden