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)
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",")"]
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()
      }
  
      _input["labels"] = torch.tensor(y).long().to(self.device)
  
      self.optimizer.zero_grad()
  
      tokenized = {
          key: value
          for (key, value) in _input.items()
          if key in self.model.forward.__code__.co_varnames
      }
  
      loss = self.model(**tokenized).loss
      self._make_step(loss)
  
      return {"loss": loss.item()}
  
file_path: DeepPavlov/deeppavlov/models/torch_bert/torch_transformers_multiplechoice.py
imports: from logging import getLogger
  from pathlib import Path
  from typing import List, Dict, Union, Optional
  import numpy
  import torch
  from transformers import AutoModelForMultipleChoice, AutoConfig
  from deeppavlov.core.common.errors import ConfigError
  from deeppavlov.core.commands.utils import expand_path
  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 TorchTransformersMultiplechoiceModel obj's underlying member method code with example usage: obj.train_on_batch(features, y) and returns: dict