code: def forward(
      self,
      input_ids: Tensor,
      attention_mask: Tensor,
      entity_pos: List,
      ner_tags: List,
      labels: List = None,
  ) -> Union[Tuple[Any, Tensor], Tuple[Tensor]]:
      if labels:
          curr_threshold = (
              None  # for training: no set threshold but adaptive one
          )
      else:
          curr_threshold = (
              self.threshold
          )  # for development and test: threshold set in config
  
      output = self.model(
          input_ids=input_ids, attention_mask=attention_mask
      )
      sequence_output = output[
          0
      ]  # Tensor (batch_size x input_length x 768)
      attention = output[-1][
          -1
      ]  # Tensor (batch_size x 12 x input_length x input_length)
  
      hs, rs, ts = self.get_hrt(
          sequence_output, attention, entity_pos
      )  # Tensors (batch_size x 768)
  
      # get ner tags of entities
      hs_ner_tags, ts_ner_tags = torch.Tensor(
          [list(ele) for ele in list(zip(*ner_tags))]
      ).to(self.device)
      hs_inp = torch.cat([hs, rs, hs_ner_tags], dim=1)
      ts_inp = torch.cat([ts, rs, ts_ner_tags], dim=1)
  
      hs = torch.tanh(self.head_extractor(hs_inp))
      ts = torch.tanh(self.tail_extractor(ts_inp))
      b1 = hs.view(
          -1, self.emb_size // self.block_size, self.block_size
      )
      b2 = ts.view(
          -1, self.emb_size // self.block_size, self.block_size
      )
      bl = (b1.unsqueeze(3) * b2.unsqueeze(2)).view(
          -1, self.emb_size * self.block_size
      )
      logits = self.bilinear(bl)
  
      output = (
          self.loss_fnt.get_label(
              logits,
              num_labels=self.n_classes,
              threshold=curr_threshold,
          ),
          logits,
      )
      if labels is not None:
          labels_tensors = [torch.tensor(label) for label in labels]
          labels_tensors = torch.stack(labels_tensors).to(logits)
          loss = self.loss_fnt(logits.float(), labels_tensors.float())
          output = (loss.to(sequence_output),) + output
      return output
  
file_path: DeepPavlov/deeppavlov/models/classifiers/re_bert.py
imports: import logging
  from pathlib import Path
  from typing import Tuple, Union, Any, List
  import torch
  from torch import Tensor
  import torch.nn
  from opt_einsum import contract
  from transformers import AutoConfig, BertModel, BertTokenizer
  from deeppavlov.core.commands.utils import expand_path
  from deeppavlov.core.common.errors import ConfigError
  from deeppavlov.models.relation_extraction.losses import ATLoss
label_desc: Use image node_id 2 for calling the BertWithAdaThresholdLocContextPooling obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, entity_pos, ner_tags, labels) and returns: output