class_docstr: Bert-based model for text classification on PyTorch.
  
  It uses output from [CLS] token and predicts labels using linear transformation.
  
  Args:
      n_classes: number of classes
      pretrained_bert: pretrained Bert checkpoint path or key title (e.g. "bert-base-uncased")
      multilabel: set True if it is multi-label classification
      return_probas: set True if return class probabilites instead of most probable label needed
      attention_probs_keep_prob: keep_prob for Bert self-attention layers
      hidden_keep_prob: keep_prob for Bert hidden layers
      bert_config_file: path to Bert configuration file (not used if pretrained_bert is key title)
      is_binary: whether classification task is binary or multi-class
      num_special_tokens: number of special tokens used by classification model
class_docstr_tok: ["Bert-based","model","for","text","classification","on","PyTorch",".","It","uses","output","from","[","CLS","]","token","and","predicts","labels","using","linear","transformation",".","Args",":","n_classes",":","number","of","classes","pretrained_bert",":","pretrained","Bert","checkpoint","path","or","key","title","(","e.g",".","``","bert-base-uncased","''",")","multilabel",":","set","True","if","it","is","multi-label","classification","return_probas",":","set","True","if","return","class","probabilites","instead","of","most","probable","label","needed","attention_probs_keep_prob",":","keep_prob","for","Bert","self-attention","layers","hidden_keep_prob",":","keep_prob","for","Bert","hidden","layers","bert_config_file",":","path","to","Bert","configuration","file","(","not","used","if","pretrained_bert","is","key","title",")","is_binary",":","whether","classification","task","is","binary","or","multi-class","num_special_tokens",":","number","of","special","tokens","used","by","classification","model"]
code: def __init__(
      self,
      n_classes,
      pretrained_bert,
      multilabel: bool = False,
      return_probas: bool = False,
      attention_probs_keep_prob: Optional[float] = None,
      hidden_keep_prob: Optional[float] = None,
      bert_config_file: Optional[str] = None,
      is_binary: Optional[bool] = False,
      num_special_tokens: int = None,
      **kwargs,
  ) -> None:
      self.return_probas = return_probas
      self.multilabel = multilabel
      self.n_classes = n_classes
      self.is_binary = is_binary
  
      if self.multilabel and not self.return_probas:
          raise RuntimeError(
              "Set return_probas to True for multilabel classification!"
          )
  
      if self.return_probas and self.n_classes == 1:
          raise RuntimeError(
              "Set return_probas to False for regression task!"
          )
  
      if pretrained_bert:
          log.debug(f"From pretrained {pretrained_bert}.")
          config = AutoConfig.from_pretrained(
              pretrained_bert,
              # num_labels=self.n_classes,
              output_attentions=False,
              output_hidden_states=False,
          )
  
          if self.is_binary:
              config.add_pooling_layer = False
              model = AutoModelForBinaryClassification(
                  pretrained_bert, config
              )
          else:
              model = (
                  AutoModelForSequenceClassification.from_pretrained(
                      pretrained_bert, config=config
                  )
              )
  
              # TODO need a better solution here and at
              # deeppavlov.models.torch_bert.torch_bert_ranker.TorchBertRankerModel.load
              try:
                  hidden_size = model.classifier.out_proj.in_features
  
                  if self.n_classes != model.num_labels:
                      model.classifier.out_proj.weight = (
                          torch.nn.Parameter(
                              torch.randn(self.n_classes, hidden_size)
                          )
                      )
                      model.classifier.out_proj.bias = (
                          torch.nn.Parameter(
                              torch.randn(self.n_classes)
                          )
                      )
                      model.classifier.out_proj.out_features = (
                          self.n_classes
                      )
                      model.num_labels = self.n_classes
  
              except AttributeError:
                  hidden_size = model.classifier.in_features
  
                  if self.n_classes != model.num_labels:
                      model.classifier.weight = torch.nn.Parameter(
                          torch.randn(self.n_classes, hidden_size)
                      )
                      model.classifier.bias = torch.nn.Parameter(
                          torch.randn(self.n_classes)
                      )
                      model.classifier.out_features = self.n_classes
                      model.num_labels = self.n_classes
  
      elif bert_config_file and Path(bert_config_file).is_file():
          bert_config = AutoConfig.from_pretrained(
              str(expand_path(bert_config_file))
          )
          if attention_probs_keep_prob is not None:
              bert_config.attention_probs_dropout_prob = (
                  1.0 - attention_probs_keep_prob
              )
          if hidden_keep_prob is not None:
              bert_config.hidden_dropout_prob = 1.0 - hidden_keep_prob
          model = AutoModelForSequenceClassification.from_config(
              config=bert_config
          )
      else:
          raise ConfigError("No pre-trained BERT model is given.")
  
      tokenizer = AutoTokenizer.from_pretrained(pretrained_bert)
      if num_special_tokens is not None:
          model.resize_token_embeddings(
              len(tokenizer) + num_special_tokens
          )
  
      super().__init__(model, **kwargs)
  
imports: from logging import getLogger
  from pathlib import Path
  from typing import List, Dict, Union, Optional, Tuple
  import numpy
  import torch
  from torch.nn import BCEWithLogitsLoss
  from transformers import AutoModelForSequenceClassification, AutoConfig, AutoModel, AutoTokenizer
  from transformers.modeling_outputs import SequenceClassifierOutput
  from deeppavlov.core.commands.utils import expand_path
  from deeppavlov.core.common.errors import ConfigError
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.models.torch_model import TorchModel
label_desc: Use image node_id 1 to create a new TorchTransformersClassifierModel object from inherited base classes: TorchModel with example: obj = TorchTransformersClassifierModel(n_classes, pretrained_bert, multilabel, return_probas, attention_probs_keep_prob, hidden_keep_prob, bert_config_file, is_binary, num_special_tokens)