code: def build_graph(self, input, nextinput):
      cell = rnn.MultiRNNCell(
          [
              rnn.LSTMBlockCell(num_units=param.rnn_size)
              for _ in range(param.num_rnn_layer)
          ]
      )
  
      def get_v(n):
          ret = tf.get_variable(
              n + "_unused",
              [param.batch_size, param.rnn_size],
              trainable=False,
              initializer=tf.constant_initializer(),
          )
          ret = tf.placeholder_with_default(
              ret, shape=[None, param.rnn_size], name=n
          )
          return ret
  
      initial = (
          rnn.LSTMStateTuple(get_v("c0"), get_v("h0")),
          rnn.LSTMStateTuple(get_v("c1"), get_v("h1")),
      )
  
      embeddingW = tf.get_variable(
          "embedding", [param.vocab_size, param.rnn_size]
      )
      input_feature = tf.nn.embedding_lookup(
          embeddingW, input
      )  # B x seqlen x rnnsize
  
      input_list = tf.unstack(
          input_feature, axis=1
      )  # seqlen x (Bxrnnsize)
  
      outputs, last_state = rnn.static_rnn(
          cell, input_list, initial, scope="rnnlm"
      )
      last_state = tf.identity(last_state, "last_state")
  
      # seqlen x (Bxrnnsize)
      output = tf.reshape(
          tf.concat(outputs, 1), [-1, param.rnn_size]
      )  # (Bxseqlen) x rnnsize
      logits = FullyConnected(
          "fc", output, param.vocab_size, activation=tf.identity
      )
      tf.nn.softmax(logits / param.softmax_temprature, name="prob")
  
      xent_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
          logits=logits, labels=tf.reshape(nextinput, [-1])
      )
      cost = tf.reduce_mean(xent_loss, name="cost")
      summary.add_param_summary(
          (".*/W", ["histogram"])
      )  # monitor histogram of all W
      summary.add_moving_summary(cost)
      return cost
  
imports: import argparse
  import numpy
  import operator
  import os
  import sys
  from collections import Counter
  import tensorflow
  from tensorpack import *
  from tensorpack.tfutils import optimizer, summary
  from tensorpack.tfutils.gradproc import GlobalNormClip
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, ret