code: def question_encoder(question, hparams, name="encoder"):
      """Question encoder, run LSTM encoder and get the last output as encoding."""
      with tf.variable_scope(name, "encoder", values=[question]):
          question = common_layers.flatten4d3d(question)
          padding = common_attention.embedding_to_padding(question)
          length = common_attention.padding_to_length(padding)
  
          max_question_length = hparams.max_question_length
          question = question[:, :max_question_length, :]
          actual_question_length = common_layers.shape_list(question)[1]
          length = tf.minimum(length, max_question_length)
          padding = [
              [0, 0],
              [0, max_question_length - actual_question_length],
              [0, 0],
          ]
          question = tf.pad(question, padding)
          question_shape = question.get_shape().as_list()
          question_shape[1] = max_question_length
          question.set_shape(question_shape)
  
          # apply tanh dropout on question embedding
          question = tf.tanh(question)
          question = tf.nn.dropout(
              question, keep_prob=1.0 - hparams.dropout
          )
  
          question = [
              question[:, i, :] for i in range(max_question_length)
          ]
  
          # rnn_layers = [_get_rnn_cell(hparams)
          #               for _ in range(hparams.num_rnn_layers)]
          # rnn_multi_cell = tf.nn.rnn_cell.MultiRNNCell(rnn_layers)
          rnn_cell = _get_rnn_cell(hparams)
          # outputs, _ = tf.nn.dynamic_rnn(
          #     rnn_cell, question, length, dtype=tf.float32)
          _, state = tf.nn.static_rnn(
              rnn_cell,
              question,
              sequence_length=length,
              dtype=tf.float32,
          )
          # outputs = [tf.expand_dims(output, axis=1) for output in outputs]
          # outputs = tf.concat(outputs, axis=1)
  
          # utils.collect_named_outputs("vqa_attention_debug", "question_output",
          #                             outputs)
          # utils.collect_named_outputs("vqa_attention_debug", "question_state",
          #                             state.h)
  
          # batch_size = common_layers.shape_list(outputs)[0]
          # row_indices = tf.range(batch_size)
          # # length - 1 as index
          # indices = tf.transpose([row_indices, tf.maximum(length-1, 0)])
          # last_output = tf.gather_nd(outputs, indices)
  
          # utils.collect_named_outputs("vqa_attention_debug",
          #                             "question_final_output", last_output)
  
      return state.h
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import vqa_layers
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  from tensorflow.contrib import rnn
  from tensorflow.contrib.layers.python.layers import utils
  from tensorflow.contrib.slim.python.slim.nets.resnet_v1 import resnet_v1_152
  from tensorflow.contrib.slim.python.slim.nets.resnet_v2 import resnet_v2_152
label_desc: Use image node_id 3 for calling a global function with example usage: question_encoder(question, hparams, name) and returns: state