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
docstr: Calculate scores for the given context over candidate responses.
  
  Args:
      features_li: list of elements where each element contains the batch of features
       for contexts with particular response candidates
  
  Returns:
      predicted scores for contexts over response candidates
docstr_tok: ["Calculate","scores","for","the","given","context","over","candidate","responses",".","Args",":","features_li",":","list","of","elements","where","each","element","contains","the","batch","of","features","for","contexts","with","particular","response","candidates","Returns",":","predicted","scores","for","contexts","over","response","candidates"]
code: def __call__(
      self, features_li: List[List[InputFeatures]]
  ) -> Union[List[int], List[List[float]]]:
      """Calculate scores for the given context over candidate responses.
  
      Args:
          features_li: list of elements where each element contains the batch of features
           for contexts with particular response candidates
  
      Returns:
          predicted scores for contexts over response candidates
      """
      if len(features_li) == 1 and len(features_li[0]) == 1:
          msg = f"It is not intended to use the {self.__class__} in the interact mode."
          log.error(msg)
          return [msg]
  
      predictions = []
      for features in features_li:
          input_ids = [f.input_ids for f in features]
          input_masks = [f.attention_mask for f in features]
  
          b_input_ids = torch.cat(input_ids, dim=0).to(self.device)
          b_input_masks = torch.cat(input_masks, dim=0).to(self.device)
  
          with torch.no_grad():
              # Forward pass, calculate logit predictions
              logits = self.model(
                  b_input_ids,
                  token_type_ids=None,
                  attention_mask=b_input_masks,
              )
              logits = logits[0]
  
          if self.return_probas:
              pred = torch.nn.functional.softmax(logits, dim=-1)[:, 1]
              pred = pred.detach().cpu().numpy()
          else:
              logits = logits.detach().cpu().numpy()
              pred = np.argmax(logits, axis=1)
  
          predictions.append(pred)
  
      if len(features_li) == 1:
          predictions = predictions[0]
      else:
          predictions = np.hstack(
              [np.expand_dims(el, 1) for el in predictions]
          )
  
      return predictions
  
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 3 for calling the TorchBertRankerModel obj's underlying member method code with example usage: obj.__call__(features_li) and returns: predictions, list