class_docstr: Class for infering of model for ranking of entities from a knowledge base by context and description
  Args:
      pretrained_bert: pretrained Bert checkpoint path or key title (e.g. "bert-base-uncased")
      encoder_weights_path: path to save the encoder checkpoint
      bilinear_weights_path: path to save bilinear layer checkpoint
      spaecial_token_id: id of special token
      do_lower_case: whether to lower case the text
      batch_size: batch size when model infering
      emb_size: entity embedding size
      block_size: size of block in bilinear layer
      device: `cpu` or `gpu` device to use
code: def __init__(
      self,
      pretrained_bert,
      encoder_weights_path,
      bilinear_weights_path,
      special_token_id: int,
      do_lower_case: bool = False,
      batch_size: int = 5,
      emb_size: int = 300,
      block_size: int = 8,
      device: str = "gpu",
      **kwargs,
  ):
      self.device = torch.device(
          "cuda"
          if torch.cuda.is_available() and device == "gpu"
          else "cpu"
      )
      self.pretrained_bert = pretrained_bert
      self.preprocessor = TorchTransformersEntityRankerPreprocessor(
          vocab_file=self.pretrained_bert,
          do_lower_case=do_lower_case,
          special_tokens=["[ENT]"],
      )
      self.encoder, self.config = None, None
      self.config = AutoConfig.from_pretrained(
          self.pretrained_bert, output_hidden_states=True
      )
      self.emb_size = emb_size
      self.block_size = block_size
      self.encoder = TextEncoder(
          pretrained_bert=self.pretrained_bert, device=self.device
      )
      self.encoder_weights_path = str(expand_path(encoder_weights_path))
      self.bilinear_weights_path = str(
          expand_path(bilinear_weights_path)
      )
      encoder_checkpoint = torch.load(
          self.encoder_weights_path, map_location=self.device
      )
      self.encoder.load_state_dict(
          encoder_checkpoint["model_state_dict"]
      )
      self.encoder.to(self.device)
      self.bilinear_ranking = BilinearRanking(
          emb_size=self.emb_size, block_size=self.block_size
      )
      bilinear_checkpoint = torch.load(
          self.bilinear_weights_path, map_location=self.device
      )
      self.bilinear_ranking.load_state_dict(
          bilinear_checkpoint["model_state_dict"]
      )
      self.bilinear_ranking.to(self.device)
      self.special_token_id = special_token_id
      self.batch_size = batch_size
  
imports: from logging import getLogger
  from pathlib import Path
  from typing import List, Optional, Dict, Tuple, Union, Any
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from transformers import AutoConfig, AutoTokenizer, AutoModel
  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.preprocessors.torch_transformers_preprocessor import TorchTransformersEntityRankerPreprocessor
label_desc: Use image node_id 1 to create a new TorchTransformersEntityRankerInfer object  with example: obj = TorchTransformersEntityRankerInfer(pretrained_bert, encoder_weights_path, bilinear_weights_path, special_token_id, do_lower_case, batch_size, emb_size, block_size, device)