docstr: labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`):
      Labels for computing the sequence classification/regression loss. Indices should be in :obj:`[0, ...,
      config.num_labels - 1]`. If :obj:`config.num_labels == 1` a regression loss is computed (Mean-Square loss),
      If :obj:`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
docstr_tok: ["labels","(",":","obj",":","`","torch.LongTensor","`","of","shape",":","obj",":","`","(","batch_size",",",")","`",",","`","optional","`",")",":","Labels","for","computing","the","sequence","classification\/regression","loss",".","Indices","should","be","in",":","obj",":","`","[","0",",","...",",","config.num_labels","-","1","]","`",".","If",":","obj",":","`","config.num_labels","==","1","`","a","regression","loss","is","computed","(","Mean-Square","loss",")",",","If",":","obj",":","`","config.num_labels",">","1","`","a","classification","loss","is","computed","(","Cross-Entropy",")","."]
code: def forward(
      self,
      input_ids=None,
      past_key_values=None,
      attention_mask=None,
      token_type_ids=None,
      position_ids=None,
      head_mask=None,
      inputs_embeds=None,
      labels=None,
      use_cache=None,
      output_attentions=None,
      output_hidden_states=None,
      return_dict=None,
  ):
      r"""
      labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`):
          Labels for computing the sequence classification/regression loss. Indices should be in :obj:`[0, ...,
          config.num_labels - 1]`. If :obj:`config.num_labels == 1` a regression loss is computed (Mean-Square loss),
          If :obj:`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
      """
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      transformer_outputs = self.transformer(
          input_ids,
          past_key_values=past_key_values,
          attention_mask=attention_mask,
          token_type_ids=token_type_ids,
          position_ids=position_ids,
          head_mask=head_mask,
          inputs_embeds=inputs_embeds,
          use_cache=use_cache,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          return_dict=return_dict,
      )
  
      hidden_states = transformer_outputs[0]
      hidden_states = self.dropout(hidden_states)
      logits = self.classifier(hidden_states)
  
      loss = None
      if labels is not None:
          loss_fct = CrossEntropyLoss()
          # Only keep active parts of the loss
          if attention_mask is not None:
              active_loss = attention_mask.view(-1) == 1
              active_logits = logits.view(-1, self.num_labels)
              active_labels = torch.where(
                  active_loss,
                  labels.view(-1),
                  torch.tensor(loss_fct.ignore_index).type_as(labels),
              )
              loss = loss_fct(active_logits, active_labels)
          else:
              loss = loss_fct(
                  logits.view(-1, self.num_labels), labels.view(-1)
              )
  
      if not return_dict:
          output = (logits,) + transformer_outputs[2:]
          return ((loss,) + output) if loss is not None else output
  
      return TokenClassifierOutput(
          loss=loss,
          logits=logits,
          hidden_states=transformer_outputs.hidden_states,
          attentions=transformer_outputs.attentions,
      )
  
imports: from dataclasses import dataclass
  from typing import Optional, Tuple
  from .configuration_gpt2 import GPT2Config
  from fastNLP.transformers.torch.activations import ACT2FN
  from fastNLP.transformers.torch.file_utils import ModelOutput, add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
  from fastNLP.transformers.torch.modeling_outputs import BaseModelOutputWithPastAndCrossAttentions, CausalLMOutputWithCrossAttentions, SequenceClassifierOutputWithPast, TokenClassifierOutput
  from fastNLP.transformers.torch.modeling_utils import Conv1D, PreTrainedModel, SequenceSummary, find_pruneable_heads_and_indices, prune_conv1d_layer
  from fastNLP.transformers.torch.utils.model_parallel_utils import assert_device_map, get_device_map
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from fastNLP.core.log import logger
label_desc: Use image node_id 2 for calling the GPT2ForTokenClassification obj's underlying member method code with example usage: obj.forward(input_ids, past_key_values, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, return_dict) and returns: TokenClassifierOutput, unknown