class_docstr: Tests :class:`~texar.tf.modules.BERTEncoder` class.
      
docstr: Tests encoding.
          
code: def test_encode(self):
      """Tests encoding."""
      # case 1: bert base
      hparams = {"pretrained_model_name": None}
      encoder = BERTEncoder(hparams=hparams)
  
      max_time = 8
      batch_size = 16
      inputs = tf.random_uniform(
          [batch_size, max_time], maxval=30521, dtype=tf.int32
      )
      outputs, pooled_output = encoder(inputs)
  
      outputs_dim = encoder.hparams.encoder.dim
      pooled_output_dim = encoder.hparams.hidden_size
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          outputs_, pooled_output_ = sess.run([outputs, pooled_output])
          self.assertEqual(
              outputs_.shape, (batch_size, max_time, outputs_dim)
          )
          self.assertEqual(
              pooled_output_.shape, (batch_size, pooled_output_dim)
          )
  
      # case 2: self-designed bert
      hparams = {"hidden_size": 100, "pretrained_model_name": None}
      encoder = BERTEncoder(hparams=hparams)
  
      max_time = 8
      batch_size = 16
      inputs = tf.random_uniform(
          [batch_size, max_time], maxval=30521, dtype=tf.int32
      )
      outputs, pooled_output = encoder(inputs)
  
      outputs_dim = encoder.hparams.encoder.dim
      pooled_output_dim = encoder.hparams.hidden_size
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          outputs_, pooled_output_ = sess.run([outputs, pooled_output])
          self.assertEqual(
              outputs_.shape, (batch_size, max_time, outputs_dim)
          )
          self.assertEqual(
              pooled_output_.shape, (batch_size, pooled_output_dim)
          )
  
file_path: texar/tests/modules/encoders/bert_encoder_test.py
imports: import tensorflow
  from texar.tf.modules.encoders.bert_encoder import BERTEncoder
  from texar.tf.utils.test import pretrained_test
label_desc: Use image node_id 4 for calling the BERTEncoderTest obj's underlying member method code with example usage: obj.test_encode() without return types