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"]
docstr: Train model on given batch.
  This method calls train_op using features and y (labels).
  
  Args:
      features: batch of InputFeatures
      y: batch of labels (class id or one-hot encoding)
  
  Returns:
      dict with loss and learning_rate values
docstr_tok: ["Train","model","on","given","batch",".","This","method","calls","train_op","using","features","and","y","(","labels",")",".","Args",":","features",":","batch","of","InputFeatures","y",":","batch","of","labels","(","class","id","or","one-hot","encoding",")","Returns",":","dict","with","loss","and","learning_rate","values"]
code: def train_on_batch(
      self,
      features: Dict[str, torch.tensor],
      y: Union[List[int], List[List[int]]],
  ) -> Dict:
      """Train model on given batch.
      This method calls train_op using features and y (labels).
  
      Args:
          features: batch of InputFeatures
          y: batch of labels (class id or one-hot encoding)
  
      Returns:
          dict with loss and learning_rate values
      """
  
      _input = {
          key: value.to(self.device) for key, value in features.items()
      }
  
      if self.n_classes > 1 and not self.is_binary:
          _input["labels"] = torch.from_numpy(np.array(y)).to(
              self.device
          )
  
      # regression
      else:
          _input["labels"] = (
              torch.from_numpy(np.array(y, dtype=np.float32))
              .unsqueeze(1)
              .to(self.device)
          )
  
      self.optimizer.zero_grad()
  
      tokenized = {
          key: value
          for (key, value) in _input.items()
          if key in self.accepted_keys
      }
  
      loss = self.model(**tokenized).loss
      if self.is_data_parallel:
          loss = loss.mean()
      self._make_step(loss)
  
      return {"loss": loss.item()}
  
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 2 for calling the TorchTransformersClassifierModel obj's underlying member method code with example usage: obj.train_on_batch(features, y) and returns: dict