code: def build_graph(self, input, nextinput):
      initializer = tf.random_uniform_initializer(-0.05, 0.05)
  
      def get_basic_cell():
          cell = rnn.BasicLSTMCell(
              num_units=HIDDEN_SIZE,
              forget_bias=0.0,
              reuse=tf.get_variable_scope().reuse,
          )
          if self.training:
              cell = rnn.DropoutWrapper(
                  cell, output_keep_prob=1 - DROPOUT
              )
          return cell
  
      cell = rnn.MultiRNNCell(
          [get_basic_cell() for _ in range(NUM_LAYER)]
      )
  
      def get_v(n):
          return tf.get_variable(
              n,
              [BATCH, HIDDEN_SIZE],
              trainable=False,
              initializer=tf.constant_initializer(),
          )
  
      state_var = [
          rnn.LSTMStateTuple(
              get_v("c{}".format(k)), get_v("h{}".format(k))
          )
          for k in range(NUM_LAYER)
      ]
      self.state = state_var = tuple(state_var)
  
      embeddingW = tf.get_variable(
          "embedding",
          [VOCAB_SIZE, HIDDEN_SIZE],
          initializer=initializer,
      )
      input_feature = tf.nn.embedding_lookup(
          embeddingW, input
      )  # B x seqlen x hiddensize
      input_feature = Dropout(input_feature, keep_prob=1 - DROPOUT)
  
      with tf.variable_scope("LSTM", initializer=initializer):
          input_list = tf.unstack(
              input_feature, num=SEQ_LEN, axis=1
          )  # seqlen x (Bxhidden)
          outputs, last_state = rnn.static_rnn(
              cell, input_list, state_var, scope="rnn"
          )
  
      # update the hidden state after a rnn loop completes
      update_state_ops = []
      for k in range(NUM_LAYER):
          update_state_ops.extend(
              [
                  tf.assign(state_var[k].c, last_state[k].c),
                  tf.assign(state_var[k].h, last_state[k].h),
              ]
          )
  
      # seqlen x (Bxrnnsize)
      output = tf.reshape(
          tf.concat(outputs, 1), [-1, HIDDEN_SIZE]
      )  # (Bxseqlen) x hidden
      logits = FullyConnected(
          "fc",
          output,
          VOCAB_SIZE,
          activation=tf.identity,
          kernel_initializer=initializer,
          bias_initializer=initializer,
      )
      xent_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
          logits=logits, labels=tf.reshape(nextinput, [-1])
      )
  
      with tf.control_dependencies(update_state_ops):
          cost = tf.truediv(
              tf.reduce_sum(xent_loss),
              tf.cast(BATCH, tf.float32),
              name="cost",
          )  # log-perplexity
  
      perpl = tf.exp(cost / SEQ_LEN, name="perplexity")
      summary.add_moving_summary(perpl, cost)
      return cost
  
file_path: tensorpack/examples/PennTreebank/PTB-LSTM.py
imports: import argparse
  import numpy
  import os
  import tensorflow
  from tensorpack import *
  from tensorpack.tfutils import gradproc, optimizer, summary
  from tensorpack.utils import logger
  from tensorpack.utils.argtools import memoized_ignoreargs
  from tensorpack.utils.fs import download, get_dataset_path
  import reader
  from reader import ptb_producer
label_desc: Use image node_id 2 for calling the Model obj's underlying member method code with example usage: obj.build_graph(input, nextinput) and returns: cost, cell, tf