class_docstr: Tests :class:`~texar.tf.modules.XLNetEncoder` class.
      
docstr: Tests encoding.
          
code: def test_encode(self):
      """Tests encoding."""
      # case 1: XLNet pre-trained
      hparams = {"pretrained_model_name": None, "untie_r": False}
      encoder = XLNetEncoder(hparams=hparams)
  
      max_time = 8
      batch_size = 128
      inputs = tf.random_uniform(
          [batch_size, max_time], maxval=30521, dtype=tf.int32
      )
      outputs, _ = encoder(inputs)
  
      outputs_dim = encoder.hparams.hidden_dim
      with self.session() as sess:
          sess.run(tf.global_variables_initializer())
          outputs_ = sess.run(outputs)
          self.assertEqual(
              outputs_.shape, (batch_size, max_time, outputs_dim)
          )
  
      # case 2: XLNet pre-trained, untie_r=True
      hparams = {"pretrained_model_name": None, "untie_r": True}
  
      encoder = XLNetEncoder(hparams=hparams)
      outputs, _ = encoder(inputs)
      with self.session() as sess:
          sess.run(tf.global_variables_initializer())
          outputs_ = sess.run(outputs)
          self.assertEqual(
              outputs_.shape, (batch_size, max_time, outputs_dim)
          )
  
      # case 3: XLNet with no pre-trained model
      hparams = {"pretrained_model_name": None}
      encoder = XLNetEncoder(hparams=hparams)
      outputs_dim = encoder.hparams.hidden_dim
      outputs, _ = encoder(inputs)
      with self.session() as sess:
          sess.run(tf.global_variables_initializer())
          outputs_ = sess.run(outputs)
          self.assertEqual(
              outputs_.shape, (batch_size, max_time, outputs_dim)
          )
  
file_path: texar/tests/modules/encoders/xlnet_encoder_test.py
imports: import tensorflow
  from texar.tf.modules.encoders.xlnet_encoder import XLNetEncoder
  from texar.tf.utils.test import pretrained_test
label_desc: Use image node_id 4 for calling the XLNetEncoderTest obj's underlying member method code with example usage: obj.test_encode() without return types