class_docstr: A class to wrap training code.
docstr: Constructor for training algorithm.
  
  Args:
      args: From command line, picked up by `argparse`.
      dataset: Currently only `data.text.Corpus` is supported.
  
  Initializes:
      - Data: train, val and test.
      - Model: shared and controller.
      - Inference: optimizers for shared and controller parameters.
      - Criticism: cross-entropy loss for training the shared model.
code: def __init__(self, args, dataset):
      """Constructor for training algorithm.
  
      Args:
          args: From command line, picked up by `argparse`.
          dataset: Currently only `data.text.Corpus` is supported.
  
      Initializes:
          - Data: train, val and test.
          - Model: shared and controller.
          - Inference: optimizers for shared and controller parameters.
          - Criticism: cross-entropy loss for training the shared model.
      """
      self.args = args
      self.controller_step = 0
      self.cuda = args.cuda
      self.dataset = dataset
      self.epoch = 0
      self.shared_step = 0
      self.start_epoch = 0
  
      logger.info("regularizing:")
      for regularizer in [
          (
              "activation regularization",
              self.args.activation_regularization,
          ),
          (
              "temporal activation regularization",
              self.args.temporal_activation_regularization,
          ),
          (
              "norm stabilizer regularization",
              self.args.norm_stabilizer_regularization,
          ),
      ]:
          if regularizer[1]:
              logger.info(f"{regularizer[0]}")
  
      self.train_data = utils.batchify(
          dataset.train, args.batch_size, self.cuda
      )
      # NOTE(brendan): The validation set data is batchified twice
      # separately: once for computing rewards during the Train Controller
      # phase (valid_data, batch size == 64), and once for evaluating ppl
      # over the entire validation set (eval_data, batch size == 1)
      self.valid_data = utils.batchify(
          dataset.valid, args.batch_size, self.cuda
      )
      self.eval_data = utils.batchify(
          dataset.valid, args.test_batch_size, self.cuda
      )
      self.test_data = utils.batchify(
          dataset.test, args.test_batch_size, self.cuda
      )
  
      self.max_length = self.args.shared_rnn_max_length
  
      if args.use_tensorboard:
          self.tb = TensorBoard(args.model_dir)
      else:
          self.tb = None
      self.build_model()
  
      if self.args.load_path:
          self.load_model()
  
      shared_optimizer = _get_optimizer(self.args.shared_optim)
      controller_optimizer = _get_optimizer(self.args.controller_optim)
  
      self.shared_optim = shared_optimizer(
          self.shared.parameters(),
          lr=self.shared_lr,
          weight_decay=self.args.shared_l2_reg,
      )
  
      self.controller_optim = controller_optimizer(
          self.controller.parameters(), lr=self.args.controller_lr
      )
  
      self.ce = nn.CrossEntropyLoss()
  
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 1 to create a new Trainer object from inherited base classes: object with example: obj = Trainer(args, dataset)