class_docstr: Raw BERT Transformer for encoding sequences. Please see
  :class:`~texar.tf.modules.PretrainedBERTMixin` for a brief description
  of BERT.
  
  This module basically stacks
  :class:`~texar.tf.modules.WordEmbedder`,
  :class:`~texar.tf.modules.PositionEmbedder`,
  :class:`~texar.tf.modules.TransformerEncoder` and a dense pooler.
  
  Args:
      pretrained_model_name (optional): a `str`, the name
          of pre-trained model (e.g., ``bert-base-uncased``). Please refer to
          :class:`~texar.tf.modules.PretrainedBERTMixin` for
          all supported models.
          If `None`, the model name in :attr:`hparams` is used.
      cache_dir (optional): the path to a folder in which the
          pre-trained models will be cached. If `None` (default),
          a default directory (``texar_data`` folder under user's home
          directory) will be used.
      hparams (dict or HParams, optional): Hyperparameters. Missing
          hyperparameter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter structure
          and default values.
  
  .. document private functions
  .. automethod:: _build
docstr: Encodes the inputs.
  
  Args:
      inputs: A 2D Tensor of shape `[batch_size, max_time]`,
          containing the token ids of tokens in the input sequences.
      segment_ids (optional): A 2D Tensor of shape
          `[batch_size, max_time]`, containing the segment ids
          of tokens in input sequences. If `None` (default), a
          tensor with all elements set to zero is used.
      sequence_length (optional): A 1D Tensor of shape `[batch_size]`.
          Input tokens beyond respective sequence lengths are masked
          out automatically.
      mode (optional): A tensor taking value in
          :tf_main:`tf.estimator.ModeKeys <estimator/ModeKeys>`,
          including `TRAIN`, `EVAL`, and `PREDICT`. Used to toggle
          dropout.
          If `None` (default), :func:`texar.tf.global_mode` is used.
      **kwargs: Keyword arguments.
  
  Returns:
      A pair :attr:`(outputs, pooled_output)`
  
          - :attr:`outputs`:  A Tensor of shape                 `[batch_size, max_time, dim]` containing the                  encoded vectors.
  
          - :attr:`pooled_output`: A Tensor of size                 `[batch_size, hidden_size]` which is the output of a                 pooler berts on top of the hidden state associated                 to the first character of the input (`CLS`), see BERT's                 paper.
docstr_tok: ["Encodes","the","inputs",".","Args",":","inputs",":","A","2D","Tensor","of","shape","`","[","batch_size",",","max_time","]","`",",","containing","the","token","ids","of","tokens","in","the","input","sequences",".","segment_ids","(","optional",")",":","A","2D","Tensor","of","shape","`","[","batch_size",",","max_time","]","`",",","containing","the","segment","ids","of","tokens","in","input","sequences",".","If","`","None","`","(","default",")",",","a","tensor","with","all","elements","set","to","zero","is","used",".","sequence_length","(","optional",")",":","A","1D","Tensor","of","shape","`","[","batch_size","]","`",".","Input","tokens","beyond","respective","sequence","lengths","are","masked","out","automatically",".","mode","(","optional",")",":","A","tensor","taking","value","in",":","tf_main",":","`","tf.estimator.ModeKeys","<","estimator\/ModeKeys",">","`",",","including","`","TRAIN","`",",","`","EVAL","`",",","and","`","PREDICT","`",".","Used","to","toggle","dropout",".","If","`","None","`","(","default",")",",",":","func",":","`","texar.tf.global_mode","`","is","used",".","*","*","kwargs",":","Keyword","arguments",".","Returns",":","A","pair",":","attr",":","`","(","outputs",",","pooled_output",")","`","-",":","attr",":","`","outputs","`",":","A","Tensor","of","shape","`","[","batch_size",",","max_time",",","dim","]","`","containing","the","encoded","vectors",".","-",":","attr",":","`","pooled_output","`",":","A","Tensor","of","size","`","[","batch_size",",","hidden_size","]","`","which","is","the","output","of","a","pooler","berts","on","top","of","the","hidden","state","associated","to","the","first","character","of","the","input","(","`","CLS","`",")",",","see","BERT","'s","paper","."]
code: def _build(
      self,
      inputs,
      sequence_length=None,
      segment_ids=None,
      mode=None,
      **kwargs,
  ):
      """Encodes the inputs.
  
          Args:
              inputs: A 2D Tensor of shape `[batch_size, max_time]`,
                  containing the token ids of tokens in the input sequences.
              segment_ids (optional): A 2D Tensor of shape
                  `[batch_size, max_time]`, containing the segment ids
                  of tokens in input sequences. If `None` (default), a
                  tensor with all elements set to zero is used.
              sequence_length (optional): A 1D Tensor of shape `[batch_size]`.
                  Input tokens beyond respective sequence lengths are masked
                  out automatically.
              mode (optional): A tensor taking value in
                  :tf_main:`tf.estimator.ModeKeys <estimator/ModeKeys>`,
                  including `TRAIN`, `EVAL`, and `PREDICT`. Used to toggle
                  dropout.
                  If `None` (default), :func:`texar.tf.global_mode` is used.
              **kwargs: Keyword arguments.
  
          Returns:
              A pair :attr:`(outputs, pooled_output)`
  
                  - :attr:`outputs`:  A Tensor of shape \
                  `[batch_size, max_time, dim]` containing the \
                   encoded vectors.
  
                  - :attr:`pooled_output`: A Tensor of size \
                  `[batch_size, hidden_size]` which is the output of a \
                  pooler berts on top of the hidden state associated \
                  to the first character of the input (`CLS`), see BERT's \
                  paper.
          """
  
      if segment_ids is None:
          segment_ids = tf.zeros_like(inputs)
  
      word_embeds = self.word_embedder(inputs)
  
      segment_embeds = self.segment_embedder(segment_ids)
  
      batch_size = tf.shape(inputs)[0]
      pos_length = tf.ones([batch_size], tf.int32) * tf.shape(inputs)[1]
      pos_embeds = self.position_embedder(sequence_length=pos_length)
  
      input_embeds = word_embeds + segment_embeds + pos_embeds
  
      if sequence_length is None:
          sequence_length = (
              tf.ones([batch_size], tf.int32) * tf.shape(inputs)[1]
          )
  
      output = self.encoder(input_embeds, sequence_length, mode)
  
      with tf.variable_scope("pooler"):
          # taking the hidden state corresponding to the first token.
          first_token_tensor = tf.squeeze(output[:, 0:1, :], axis=1)
          pooled_output = self.pooler(first_token_tensor)
  
      if not self._built:
          self._add_internal_trainable_variables()
          self._built = True
  
          self.init_pretrained_weights(self.variable_scope.name)
  
      return output, pooled_output
  
file_path: texar/texar/tf/modules/encoders/bert_encoder.py
imports: import tensorflow
  from texar.tf.core.layers import get_initializer, get_layer
  from texar.tf.modules.encoders.transformer_encoders import TransformerEncoder
  from texar.tf.modules.embedders.embedders import WordEmbedder
  from texar.tf.modules.embedders.position_embedders import PositionEmbedder
  from texar.tf.modules.encoders.encoder_base import EncoderBase
  from texar.tf.modules.pretrained.bert import PretrainedBERTMixin
label_desc: Use image node_id 4 for calling the BERTEncoder obj's underlying member method code with example usage: obj._build(inputs, sequence_length, segment_ids, mode) and returns: output,  pooled_output