class_docstr: Tests :class:`~texar.tf.modules.BidirectionalRNNEncoder` class.
      
class_docstr_tok: ["Tests",":","class",":","`","~texar.tf.modules.BidirectionalRNNEncoder","`","class","."]
docstr: Tests encoding.
          
docstr_tok: ["Tests","encoding","."]
code: def test_encode(self):
      """Tests encoding."""
      # case 1
      encoder = BidirectionalRNNEncoder()
  
      max_time = 8
      batch_size = 16
      emb_dim = 100
      inputs = tf.random_uniform(
          [batch_size, max_time, emb_dim], maxval=1.0, dtype=tf.float32
      )
      outputs, state = encoder(inputs)
  
      cell_dim = encoder.hparams.rnn_cell_fw.kwargs.num_units
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          outputs_, state_ = sess.run([outputs, state])
          self.assertEqual(
              outputs_[0].shape, (batch_size, max_time, cell_dim)
          )
          self.assertEqual(state_[0][0].shape, (batch_size, cell_dim))
  
      # case 2: with output layers
      hparams = {
          "output_layer_fw": {
              "num_layers": 2,
              "layer_size": [100, 6],
              "dropout_layer_ids": [0, 1, 2],
              "variational_dropout": True,
          }
      }
      encoder = BidirectionalRNNEncoder(hparams=hparams)
  
      max_time = 8
      batch_size = 16
      emb_dim = 100
      inputs = tf.random_uniform(
          [batch_size, max_time, emb_dim], maxval=1.0, dtype=tf.float32
      )
      outputs, state, cell_outputs, output_size = encoder(
          inputs, return_cell_output=True, return_output_size=True
      )
  
      self.assertEqual(output_size[0][0], 6)
      self.assertEqual(output_size[1][0], 6)
      self.assertEqual(
          cell_outputs[0].shape[-1], encoder.cell_fw.output_size
      )
      self.assertEqual(
          cell_outputs[1].shape[-1], encoder.cell_bw.output_size
      )
  
      out_dim = encoder.hparams.output_layer_fw.layer_size[-1]
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          outputs_ = sess.run(outputs)
          self.assertEqual(
              outputs_[0].shape, (batch_size, max_time, out_dim)
          )
          self.assertEqual(
              outputs_[1].shape, (batch_size, max_time, out_dim)
          )
  
file_path: texar/tests/modules/encoders/rnn_encoders_test.py
imports: import tensorflow
  from texar.tf.modules.encoders.rnn_encoders import UnidirectionalRNNEncoder
  from texar.tf.modules.encoders.rnn_encoders import BidirectionalRNNEncoder
  from texar.tf.modules.embedders.embedders import WordEmbedder
label_desc: Use image node_id 2 for calling the BidirectionalRNNEncoderTest obj's underlying member method code with example usage: obj.test_encode() without return types