class_docstr: Classifier based on GPT2 modules. Please see
  :class:`~texar.tf.modules.PretrainedGPT2Mixin` for a brief description
  of GPT2.
  
  This is a combination of the
  :class:`~texar.tf.modules.GPT2Encoder` with a classification
  layer. Both step-wise classification and sequence-level classification
  are supported, specified in :attr:`hparams`.
  
  Arguments are the same as in
  :class:`~texar.tf.modules.GPT2Encoder`.
  
  Args:
      pretrained_model_name (optional): a `str`, the name
          of pre-trained model (e.g., ``gpt2-small``). Please refer to
          :class:`~texar.tf.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.
  
  .. document private functions
  .. automethod:: _build
class_docstr_tok: ["Classifier","based","on","GPT2","modules",".","Please","see",":","class",":","`","~texar.tf.modules.PretrainedGPT2Mixin","`","for","a","brief","description","of","GPT2",".","This","is","a","combination","of","the",":","class",":","`","~texar.tf.modules.GPT2Encoder","`","with","a","classification","layer",".","Both","step-wise","classification","and","sequence-level","classification","are","supported",",","specified","in",":","attr",":","`","hparams","`",".","Arguments","are","the","same","as","in",":","class",":","`","~texar.tf.modules.GPT2Encoder","`",".","Args",":","pretrained_model_name","(","optional",")",":","a","`","str","`",",","the","name","of","pre-trained","model","(","e.g.",",","``","gpt2-small","``",")",".","Please","refer","to",":","class",":","`","~texar.tf.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",".","..","document","private","functions","..","automethod",":",":","_build"]
docstr: Returns a dictionary of hyperparameters with default values.
  
  .. code-block:: python
  
      {
          # (1) Same hyperparameters as in GPT2Encoder
          ...
          # (2) Additional hyperparameters
          "num_classes": 2,
          "logit_layer_kwargs": None,
          "clas_strategy": `cls_time`,
          "max_seq_length": None,
          "dropout": 0.1,
          "name": `gpt2_classifier`
      }
  
  Here:
  
  1. Same hyperparameters as in
  :class:`~texar.tf.modules.GPT2Encoder`.
  See the :meth:`~texar.tf.modules.GPT2Encoder.default_hparams`.
  An instance of GPT2Encoder is created for feature extraction.
  
  2. Additional hyperparameters:
  
      `"num_classes"`: int
          Number of classes:
  
          - If **> 0**, an additional :tf_main:`Dense <layers/Dense>`
            layer is appended to the encoder to compute the logits over
            classes.
          - If **<= 0**, no dense layer is appended. The number of
            classes is assumed to be the final dense layer size of the
            encoder.
  
      `"logit_layer_kwargs"`: dict
          Keyword arguments for the logit Dense layer constructor,
          except for argument "units" which is set to `num_classes`.
          Ignored if no extra logit layer is appended.
  
      `"clas_strategy"`: str
          The classification strategy, one of:
  
          - **cls_time**: Sequence-level classification based on the
            output of the first time step (which is the `CLS` token).
            Each sequence has a class.
          - **all_time**: Sequence-level classification based on
            the output of all time steps. Each sequence has a class.
          - **time_wise**: Step-wise classification, i.e., make
            classification for each time step based on its output.
  
      `"max_seq_length"`: int, optional
          Maximum possible length of input sequences. Required if
          `clas_strategy` is `all_time`.
  
      `"dropout"`: float
          The dropout rate of the BERT encoder output.
  
      `"name"`: str
          Name of the classifier.
docstr_tok: ["Returns","a","dictionary","of","hyperparameters","with","default","values",".","..","code-block",":",":","python","{","#","(","1",")","Same","hyperparameters","as","in","GPT2Encoder","...","#","(","2",")","Additional","hyperparameters","``","num_classes","''",":","2",",","``","logit_layer_kwargs","''",":","None",",","``","clas_strategy","''",":","`","cls_time","`",",","``","max_seq_length","''",":","None",",","``","dropout","''",":","0.1",",","``","name","''",":","`","gpt2_classifier","`","}","Here",":","1",".","Same","hyperparameters","as","in",":","class",":","`","~texar.tf.modules.GPT2Encoder","`",".","See","the",":","meth",":","`","~texar.tf.modules.GPT2Encoder.default_hparams","`",".","An","instance","of","GPT2Encoder","is","created","for","feature","extraction",".","2",".","Additional","hyperparameters",":","`","``","num_classes","''","`",":","int","Number","of","classes",":","-","If","*","*",">","0","*","*",",","an","additional",":","tf_main",":","`","Dense","<","layers\/Dense",">","`","layer","is","appended","to","the","encoder","to","compute","the","logits","over","classes",".","-","If","*","*","<","=","0","*","*",",","no","dense","layer","is","appended",".","The","number","of","classes","is","assumed","to","be","the","final","dense","layer","size","of","the","encoder",".","`","``","logit_layer_kwargs","''","`",":","dict","Keyword","arguments","for","the","logit","Dense","layer","constructor",",","except","for","argument","``","units","''","which","is","set","to","`","num_classes","`",".","Ignored","if","no","extra","logit","layer","is","appended",".","`","``","clas_strategy","''","`",":","str","The","classification","strategy",",","one","of",":","-","*","*","cls_time","*","*",":","Sequence-level","classification","based","on","the","output","of","the","first","time","step","(","which","is","the","`","CLS","`","token",")",".","Each","sequence","has","a","class",".","-","*","*","all_time","*","*",":","Sequence-level","classification","based","on","the","output","of","all","time","steps",".","Each","sequence","has","a","class",".","-","*","*","time_wise","*","*",":","Step-wise","classification",",","i.e.",",","make","classification","for","each","time","step","based","on","its","output",".","`","``","max_seq_length","''","`",":","int",",","optional","Maximum","possible","length","of","input","sequences",".","Required","if","`","clas_strategy","`","is","`","all_time","`",".","`","``","dropout","''","`",":","float","The","dropout","rate","of","the","BERT","encoder","output",".","`","``","name","''","`",":","str","Name","of","the","classifier","."]
code: def default_hparams():
      r"""Returns a dictionary of hyperparameters with default values.
  
      .. code-block:: python
  
          {
              # (1) Same hyperparameters as in GPT2Encoder
              ...
              # (2) Additional hyperparameters
              "num_classes": 2,
              "logit_layer_kwargs": None,
              "clas_strategy": `cls_time`,
              "max_seq_length": None,
              "dropout": 0.1,
              "name": `gpt2_classifier`
          }
  
      Here:
  
      1. Same hyperparameters as in
      :class:`~texar.tf.modules.GPT2Encoder`.
      See the :meth:`~texar.tf.modules.GPT2Encoder.default_hparams`.
      An instance of GPT2Encoder is created for feature extraction.
  
      2. Additional hyperparameters:
  
          `"num_classes"`: int
              Number of classes:
  
              - If **> 0**, an additional :tf_main:`Dense <layers/Dense>`
                layer is appended to the encoder to compute the logits over
                classes.
              - If **<= 0**, no dense layer is appended. The number of
                classes is assumed to be the final dense layer size of the
                encoder.
  
          `"logit_layer_kwargs"`: dict
              Keyword arguments for the logit Dense layer constructor,
              except for argument "units" which is set to `num_classes`.
              Ignored if no extra logit layer is appended.
  
          `"clas_strategy"`: str
              The classification strategy, one of:
  
              - **cls_time**: Sequence-level classification based on the
                output of the first time step (which is the `CLS` token).
                Each sequence has a class.
              - **all_time**: Sequence-level classification based on
                the output of all time steps. Each sequence has a class.
              - **time_wise**: Step-wise classification, i.e., make
                classification for each time step based on its output.
  
          `"max_seq_length"`: int, optional
              Maximum possible length of input sequences. Required if
              `clas_strategy` is `all_time`.
  
          `"dropout"`: float
              The dropout rate of the BERT encoder output.
  
          `"name"`: str
              Name of the classifier.
      """
      hparams = GPT2Encoder.default_hparams()
      hparams.update(
          {
              "num_classes": 2,
              "logit_layer_kwargs": None,
              "clas_strategy": "cls_time",
              "max_seq_length": None,
              "dropout": 0.1,
              "name": "gpt2_classifier",
          }
      )
      return hparams
  
file_path: texar/texar/tf/modules/classifiers/gpt2_classifier.py
imports: import tensorflow
  from texar.tf.core.layers import get_layer
  from texar.tf.modules.classifiers.classifier_base import ClassifierBase
  from texar.tf.modules.encoders.gpt2_encoder import GPT2Encoder
  from texar.tf.hyperparams import HParams
  from texar.tf.modules.pretrained.gpt2 import PretrainedGPT2Mixin
  from texar.tf.utils.utils import dict_fetch
label_desc: Use image node_id 2 for calling the GPT2Classifier obj's underlying member method code with example usage: obj.default_hparams() and returns: hparams