class_docstr: Classification head and pooler.
class_docstr_tok: ["Classification","head","and","pooler","."]
code: def forward(
      self,
      input_ids,
      attention_mask: Optional[torch.Tensor] = None,
      labels: Optional[torch.Tensor] = None,
      **kwargs,
  ):
      logits = self.head(
          self.pooler(self.encoder(input_ids, attention_mask))
      )
  
      if labels is not None:
          if self.problem_type is None:  # very much from huggingface
              if self.num_labels == 1:
                  self.problem_type = "regression"
              elif self.num_labels > 1 and (
                  labels.dtype == torch.long
                  or labels.dtype == torch.int
              ):
                  self.problem_type = "single_label_classification"
              else:
                  self.problem_type = "multi_label_classification"
  
          if self.problem_type == "regression":
              loss_fct = torch.nn.MSELoss()
              if self.num_labels == 1:
                  loss = loss_fct(logits.squeeze(), labels.squeeze())
              else:
                  loss = loss_fct(logits, labels)
          elif self.problem_type == "single_label_classification":
              loss_fct = torch.nn.CrossEntropyLoss()
              loss = loss_fct(
                  logits.view(-1, self.num_labels), labels.view(-1)
              )
          elif self.problem_type == "multi_label_classification":
              loss_fct = torch.nn.BCEWithLogitsLoss()
              loss = loss_fct(logits, labels)
      else:
          loss = logits.new_zeros((1,))
  
      return dict(logits=logits, loss=loss)
  
imports: import torch
  from transformers import PretrainedConfig, PreTrainedModel
  from transformers import AutoConfig, AutoModel, AutoModelForMaskedLM, AutoModelForSequenceClassification, AutoModelForTokenClassification
  from typing import Optional
  from omegaconf import OmegaConf
  from .fff import FFF
  from .components import _get_norm_fn, _get_nonlin_fn, EmbeddingComponent, PoolingComponent, PredictionHeadComponent, GLU, get_extended_attention_mask, _init_module
  from .attention import get_attention_mechanism
label_desc: Use image node_id 3 for calling the ScriptableLMForSequenceClassification obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, labels) and returns: dict