docstr: Args:
      token: (B, L), index of tokens
      att_mask: (B, L), attention mask (1 for contents and 0 for padding)
      pos1: (B, 1), position of the head entity starter
      pos2: (B, 1), position of the tail entity starter
  Return:
      (B, 2H), representations for sentences
docstr_tok: ["Args",":","token",":","(","B",",","L",")",",","index","of","tokens","att_mask",":","(","B",",","L",")",",","attention","mask","(","1","for","contents","and","0","for","padding",")","pos1",":","(","B",",","1",")",",","position","of","the","head","entity","starter","pos2",":","(","B",",","1",")",",","position","of","the","tail","entity","starter","Return",":","(","B",",","2H",")",",","representations","for","sentences"]
code: def forward(self, token, att_mask, pos1, pos2):
      """
      Args:
          token: (B, L), index of tokens
          att_mask: (B, L), attention mask (1 for contents and 0 for padding)
          pos1: (B, 1), position of the head entity starter
          pos2: (B, 1), position of the tail entity starter
      Return:
          (B, 2H), representations for sentences
      """
      hidden, _ = self.bert(
          token, attention_mask=att_mask, return_dict=False
      )
      # Get entity start hidden state
      onehot_head = (
          torch.zeros(hidden.size()[:2]).float().to(hidden.device)
      )  # (B, L)
      onehot_tail = (
          torch.zeros(hidden.size()[:2]).float().to(hidden.device)
      )  # (B, L)
      onehot_head = onehot_head.scatter_(1, pos1, 1)
      onehot_tail = onehot_tail.scatter_(1, pos2, 1)
      head_hidden = (onehot_head.unsqueeze(2) * hidden).sum(1)  # (B, H)
      tail_hidden = (onehot_tail.unsqueeze(2) * hidden).sum(1)  # (B, H)
      x = torch.cat([head_hidden, tail_hidden], 1)  # (B, 2H)
      x = self.linear(x)
      return x
  
file_path: OpenNRE/opennre/encoder/bert_encoder.py
imports: import logging
  import torch
  import torch.nn
  from transformers import BertModel, BertTokenizer
  from .base_encoder import BaseEncoder
label_desc: Use image node_id 2 for calling the BERTEntityEncoder obj's underlying member method code with example usage: obj.forward(token, att_mask, pos1, pos2) and returns: x