class_docstr: Pre-trained GPT2 Tokenizer.
  
  Args:
      pretrained_model_name (optional): a `str`, the name of
          pre-trained model (e.g., `117M`). Please refer to
          :class:`~texar.torch.modules.PretrainedGPT2Mixin` 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.
class_docstr_tok: ["Pre-trained","GPT2","Tokenizer",".","Args",":","pretrained_model_name","(","optional",")",":","a","`","str","`",",","the","name","of","pre-trained","model","(","e.g.",",","`","117M","`",")",".","Please","refer","to",":","class",":","`","~texar.torch.modules.PretrainedGPT2Mixin","`","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","."]
docstr: Adds special tokens to a sequence and computes the corresponding
  sequence length for GPT2 specific tasks. The sequence will be truncated
  if its length is larger than ``max_seq_length``.
  
  A GPT2 sequence has the following format:
  `[bos_token]` X `[eos_token]` `[pad_token]`
  
  Args:
      text: Input text.
      max_seq_length: Maximum sequence length.
      append_eos_token: Whether to append ``eos_token`` after the
          sequence.
  
  Returns:
      A tuple of `(input_ids, seq_len)`, where
  
      - ``input_ids``: A list of input token ids with added
        special tokens.
      - ``seq_len``: The sequence length.
docstr_tok: ["Adds","special","tokens","to","a","sequence","and","computes","the","corresponding","sequence","length","for","GPT2","specific","tasks",".","The","sequence","will","be","truncated","if","its","length","is","larger","than","``","max_seq_length","``",".","A","GPT2","sequence","has","the","following","format",":","`","[","bos_token","]","`","X","`","[","eos_token","]","`","`","[","pad_token","]","`","Args",":","text",":","Input","text",".","max_seq_length",":","Maximum","sequence","length",".","append_eos_token",":","Whether","to","append","``","eos_token","``","after","the","sequence",".","Returns",":","A","tuple","of","`","(","input_ids",",","seq_len",")","`",",","where","-","``","input_ids","``",":","A","list","of","input","token","ids","with","added","special","tokens",".","-","``","seq_len","``",":","The","sequence","length","."]
code: def encode_text(  # type: ignore
      self,
      text: str,
      max_seq_length: Optional[int] = None,
      append_eos_token: bool = True,
  ) -> Tuple[List[int], int]:
      r"""Adds special tokens to a sequence and computes the corresponding
      sequence length for GPT2 specific tasks. The sequence will be truncated
      if its length is larger than ``max_seq_length``.
  
      A GPT2 sequence has the following format:
      `[bos_token]` X `[eos_token]` `[pad_token]`
  
      Args:
          text: Input text.
          max_seq_length: Maximum sequence length.
          append_eos_token: Whether to append ``eos_token`` after the
              sequence.
  
      Returns:
          A tuple of `(input_ids, seq_len)`, where
  
          - ``input_ids``: A list of input token ids with added
            special tokens.
          - ``seq_len``: The sequence length.
      """
      if max_seq_length is None:
          max_seq_length = self.max_len
  
      token_ids = self.map_text_to_id(text)
      assert isinstance(token_ids, list)
  
      bos_token_id = self._map_token_to_id(self.bos_token)
      eos_token_id = self._map_token_to_id(self.eos_token)
      pad_token_id = self._map_token_to_id(self.pad_token)
  
      if append_eos_token:
          input_ids = token_ids[: max_seq_length - 2]
          input_ids = [bos_token_id] + input_ids + [eos_token_id]
      else:
          input_ids = token_ids[: max_seq_length - 1]
          input_ids = [bos_token_id] + input_ids
  
      seq_len = len(input_ids)
  
      # Pad up to the maximum sequence length.
      input_ids = input_ids + [pad_token_id] * (
          max_seq_length - seq_len
      )
  
      assert len(input_ids) == max_seq_length
  
      return input_ids, seq_len
  
imports: from typing import Any, Dict, List, Optional, Tuple
  import os
  import json
  import regex
  from texar.tf.modules.pretrained.gpt2 import PretrainedGPT2Mixin
  from texar.tf.data.tokenizers.tokenizer_base import TokenizerBase
  from texar.tf.data.tokenizers.gpt2_tokenizer_utils import bytes_to_unicode, get_pairs
label_desc: Use image node_id 9 for calling the GPT2Tokenizer obj's underlying member method code with example usage: obj.encode_text(text, max_seq_length, append_eos_token) and returns: input_ids,  seq_len