class_docstr: Transformer-based model on PyTorch for text tagging. It predicts a label for every token (not subtoken)
  in the text. You can use it for sequence labeling tasks, such as morphological tagging or named entity recognition.
  
  Args:
      n_tags: number of distinct tags
      pretrained_bert: pretrained Bert checkpoint path or key title (e.g. "bert-base-uncased")
      bert_config_file: path to Bert configuration file, or None, if `pretrained_bert` is a string name
      attention_probs_keep_prob: keep_prob for Bert self-attention layers
      hidden_keep_prob: keep_prob for Bert hidden layers
      use_crf: whether to use Conditional Ramdom Field to decode tags
class_docstr_tok: ["Transformer-based","model","on","PyTorch","for","text","tagging",".","It","predicts","a","label","for","every","token","(","not","subtoken",")","in","the","text",".","You","can","use","it","for","sequence","labeling","tasks",",","such","as","morphological","tagging","or","named","entity","recognition",".","Args",":","n_tags",":","number","of","distinct","tags","pretrained_bert",":","pretrained","Bert","checkpoint","path","or","key","title","(","e.g",".","``","bert-base-uncased","''",")","bert_config_file",":","path","to","Bert","configuration","file",",","or","None",",","if","`","pretrained_bert","`","is","a","string","name","attention_probs_keep_prob",":","keep_prob","for","Bert","self-attention","layers","hidden_keep_prob",":","keep_prob","for","Bert","hidden","layers","use_crf",":","whether","to","use","Conditional","Ramdom","Field","to","decode","tags"]
docstr: Args:
      input_ids: batch of indices of subwords
      input_masks: batch of masks which determine what should be attended
      args: arguments passed  to _build_feed_dict
          and corresponding to additional input
          and output tensors of the derived class.
      kwargs: keyword arguments passed to _build_feed_dict
          and corresponding to additional input
          and output tensors of the derived class.
  
  Returns:
      dict with fields 'loss', 'head_learning_rate', and 'bert_learning_rate'
docstr_tok: ["Args",":","input_ids",":","batch","of","indices","of","subwords","input_masks",":","batch","of","masks","which","determine","what","should","be","attended","args",":","arguments","passed","to","_build_feed_dict","and","corresponding","to","additional","input","and","output","tensors","of","the","derived","class",".","kwargs",":","keyword","arguments","passed","to","_build_feed_dict","and","corresponding","to","additional","input","and","output","tensors","of","the","derived","class",".","Returns",":","dict","with","fields","'loss","'",",","'head_learning_rate","'",",","and","'bert_learning_rate","'"]
code: def train_on_batch(
      self,
      input_ids: Union[List[List[int]], np.ndarray],
      input_masks: Union[List[List[int]], np.ndarray],
      y_masks: Union[List[List[int]], np.ndarray],
      y: List[List[int]],
      *args,
      **kwargs,
  ) -> Dict[str, float]:
      """
  
      Args:
          input_ids: batch of indices of subwords
          input_masks: batch of masks which determine what should be attended
          args: arguments passed  to _build_feed_dict
              and corresponding to additional input
              and output tensors of the derived class.
          kwargs: keyword arguments passed to _build_feed_dict
              and corresponding to additional input
              and output tensors of the derived class.
  
      Returns:
          dict with fields 'loss', 'head_learning_rate', and 'bert_learning_rate'
      """
      b_input_ids = torch.from_numpy(input_ids).to(self.device)
      b_input_masks = torch.from_numpy(input_masks).to(self.device)
      subtoken_labels = [
          token_labels_to_subtoken_labels(y_el, y_mask, input_mask)
          for y_el, y_mask, input_mask in zip(y, y_masks, input_masks)
      ]
      b_labels = (
          torch.from_numpy(np.array(subtoken_labels))
          .to(torch.int64)
          .to(self.device)
      )
      self.optimizer.zero_grad()
  
      loss = self.model(
          input_ids=b_input_ids,
          attention_mask=b_input_masks,
          labels=b_labels,
      ).loss
      if self.crf is not None:
          self.crf(y, y_masks)
      if self.is_data_parallel:
          loss = loss.mean()
      self._make_step(loss)
  
      return {"loss": loss.item()}
  
file_path: DeepPavlov/deeppavlov/models/torch_bert/torch_transformers_sequence_tagger.py
imports: from logging import getLogger
  from pathlib import Path
  from typing import List, Union, Dict, Optional, Tuple
  import numpy
  import torch
  from transformers import AutoModelForTokenClassification, AutoConfig
  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
  from deeppavlov.models.torch_bert.crf import CRF
label_desc: Use image node_id 2 for calling the TorchTransformersSequenceTagger obj's underlying member method code with example usage: obj.train_on_batch(input_ids, input_masks, y_masks, y) and returns: dict