class_docstr: Main class that defines training graph and defines training run method for language modeling
class_docstr_tok: ["Main","class","that","defines","training","graph","and","defines","training","run","method","for","language","modeling"]
docstr: Args:
      data_loaders: dict, keys are "train", "valid", "test",
                    values are corresponding iterator dataloaders
      lr: float, learning rate
      num_iterations: int, number of iterations to run
      log_interval: int, number of iterations after which to run validation and log
      result_dir: str, path to results directory
      ckpt: str, location of checkpoint file
  
  Returns:
      None
docstr_tok: ["Args",":","data_loaders",":","dict",",","keys","are","``","train","''",",","``","valid","''",",","``","test","''",",","values","are","corresponding","iterator","dataloaders","lr",":","float",",","learning","rate","num_iterations",":","int",",","number","of","iterations","to","run","log_interval",":","int",",","number","of","iterations","after","which","to","run","validation","and","log","result_dir",":","str",",","path","to","results","directory","ckpt",":","str",",","location","of","checkpoint","file","Returns",":","None"]
code: def run(
      self,
      data_loaders,
      lr,
      num_iterations=100,
      log_interval=100,
      result_dir="./",
      ckpt=None,
  ):
      """
      Args:
          data_loaders: dict, keys are "train", "valid", "test",
                        values are corresponding iterator dataloaders
          lr: float, learning rate
          num_iterations: int, number of iterations to run
          log_interval: int, number of iterations after which to run validation and log
          result_dir: str, path to results directory
          ckpt: str, location of checkpoint file
  
      Returns:
          None
      """
  
      summary_writer = tf.summary.FileWriter(
          os.path.join(result_dir, "tfboard"), tf.get_default_graph()
      )
      saver = tf.train.Saver(max_to_keep=None)
  
      sess = tf.Session(
          config=tf.ConfigProto(allow_soft_placement=True)
      )
      init = tf.group(
          tf.global_variables_initializer(),
          tf.local_variables_initializer(),
      )
      sess.run(init)
  
      if ckpt is not None:
          saver.restore(sess, ckpt)
  
      all_vloss = []
      for i in range(num_iterations):
          x_data, y_data = next(data_loaders["train"])
  
          feed_dict = {
              self.input_placeholder_tokens: x_data,
              self.label_placeholder_tokens: y_data,
              self.training_mode: True,
              self.learning_rate: lr,
          }
          _, summary_train, total_loss_i = sess.run(
              [
                  self.training_update_step,
                  self.merged_summary_op_train,
                  self.training_loss,
              ],
              feed_dict=feed_dict,
          )
  
          summary_writer.add_summary(summary_train, i)
  
          if i % log_interval == 0:
              print("Step {}: Total: {}".format(i, total_loss_i))
              saver.save(sess, result_dir, global_step=i)
  
              val_loss = {}
              for split_type in ["valid", "test"]:
                  val_loss[split_type] = 0
                  data_loaders[split_type].reset()
                  count = 0
                  for x_data_test, y_data_test in data_loaders[
                      split_type
                  ]:
                      feed_dict = {
                          self.input_placeholder_tokens: x_data_test,
                          self.label_placeholder_tokens: y_data_test,
                          self.training_mode: False,
                      }
                      val_loss[split_type] += sess.run(
                          self.training_loss, feed_dict=feed_dict
                      )
                      count += 1
  
                  val_loss[split_type] = val_loss[split_type] / count
  
              summary_val = sess.run(
                  self.merged_summary_op_val,
                  feed_dict={self.validation_loss: val_loss["valid"]},
              )
              summary_test = sess.run(
                  self.merged_summary_op_test,
                  feed_dict={self.test_loss: val_loss["test"]},
              )
  
              summary_writer.add_summary(summary_val, i)
              summary_writer.add_summary(summary_test, i)
  
              print("Validation loss: {}".format(val_loss["valid"]))
              print("Test loss: {}".format(val_loss["test"]))
              all_vloss.append(val_loss["valid"])
  
              if i > 3 * log_interval and val_loss["valid"] >= max(
                  all_vloss[-5:]
              ):
                  lr = lr / 2.0
  
file_path: nlp-architect/examples/word_language_model_with_tcn/mle_language_model/lm_model.py
imports: import os
  import numpy
  import tensorflow
  from tqdm import tqdm
  from nlp_architect.models.temporal_convolutional_network import TCN, CommonLayers
label_desc: Use image node_id 2 for calling the TCNForLM obj's underlying member method code with example usage: obj.run(data_loaders, lr, num_iterations, log_interval, result_dir, ckpt) without return types