class_docstr: BERT-based model for interaction-based text ranking on PyTorch.
  
  Linear transformation is trained over the BERT pooled output from [CLS] token.
  Predicted probabilities of classes are used as a similarity measure for ranking.
  
  Args:
      pretrained_bert: pretrained Bert checkpoint path or key title (e.g. "bert-base-uncased")
      bert_config_file: path to Bert configuration file (not used if pretrained_bert is key title)
      n_classes: number of classes
      return_probas: set True if class probabilities are returned instead of the most probable label
code: def __init__(
      self,
      pretrained_bert: str = None,
      bert_config_file: Optional[str] = None,
      n_classes: int = 2,
      return_probas: bool = True,
      **kwargs,
  ) -> None:
      self.return_probas = return_probas
  
      if self.return_probas and n_classes == 1:
          raise RuntimeError(
              "Set return_probas to False for regression task!"
          )
  
      if pretrained_bert:
          log.debug(f"From pretrained {pretrained_bert}.")
          if Path(expand_path(pretrained_bert)).exists():
              pretrained_bert = str(expand_path(pretrained_bert))
          config = AutoConfig.from_pretrained(
              pretrained_bert,
              # num_labels=self.n_classes,
              output_attentions=False,
              output_hidden_states=False,
          )
  
          model = AutoModelForSequenceClassification.from_pretrained(
              pretrained_bert, config=config
          )
  
          # TODO: make better exception handling here and at
          # deeppavlov.models.torch_bert.torch_transformers_classifier.TorchTransformersClassifierModel.load
          try:
              hidden_size = model.classifier.out_proj.in_features
  
              if n_classes != model.num_labels:
                  model.classifier.out_proj.weight = torch.nn.Parameter(
                      torch.randn(n_classes, hidden_size)
                  )
                  model.classifier.out_proj.bias = torch.nn.Parameter(
                      torch.randn(n_classes)
                  )
                  model.classifier.out_proj.out_features = n_classes
                  model.num_labels = n_classes
  
          except AttributeError:
              hidden_size = model.classifier.in_features
  
              if n_classes != model.num_labels:
                  model.classifier.weight = torch.nn.Parameter(
                      torch.randn(n_classes, hidden_size)
                  )
                  model.classifier.bias = torch.nn.Parameter(
                      torch.randn(n_classes)
                  )
                  model.classifier.out_features = n_classes
                  model.num_labels = n_classes
  
      elif bert_config_file and expand_path(bert_config_file).is_file():
          self.bert_config = AutoConfig.from_pretrained(
              str(expand_path(bert_config_file))
          )
          model = AutoModelForSequenceClassification.from_config(
              config=self.bert_config
          )
  
      else:
          raise ConfigError("No pre-trained BERT model is given.")
  
      super().__init__(model, **kwargs)
  
file_path: DeepPavlov/deeppavlov/models/torch_bert/torch_bert_ranker.py
imports: from logging import getLogger
  from pathlib import Path
  from typing import List, Dict, Union, Optional
  import numpy
  import torch
  from transformers import AutoModelForSequenceClassification, AutoConfig
  from transformers.data.processors.utils import InputFeatures
  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 TorchBertRankerModel object from inherited base classes: TorchModel with example: obj = TorchBertRankerModel(pretrained_bert, bert_config_file, n_classes, return_probas)