code: def forward(
      self,
      input_ids=None,
      attention_mask=None,
      labels=None,
      entity_pos=None,
      hts=None,
      instance_mask=None,
  ):
      sequence_output, attention = self.encode(
          input_ids, attention_mask, entity_pos
      )
  
      bs, sequen_len, d = sequence_output.shape
      run_device = sequence_output.device.index
      ne = max([len(x) for x in entity_pos])  # 本次bs中的最大实体数
      ent_mask, rel_mask = self.get_mask(entity_pos, bs, ne, run_device)
  
      # get hs, ts and entity_embs >> entity_rs
      hs, ts, entity_embs, entity_as = self.get_hrt(
          sequence_output, attention, entity_pos, hts
      )
  
      if self.channel_type == "context-based":
          feature_map = self.get_channel_map(sequence_output, entity_as)
          ##print('feature_map:', feature_map.shape)
          attn_input = (
              self.liner(feature_map).permute(0, 3, 1, 2).contiguous()
          )
  
      else:
          raise Exception("channel_type must be specify correctly")
  
      attn_map = self.segmentation_net(attn_input)
      h_t = self.get_ht(attn_map, hts)
  
      hs = torch.tanh(self.head_extractor(torch.cat([hs, h_t], dim=1)))
      ts = torch.tanh(self.tail_extractor(torch.cat([ts, h_t], dim=1)))
  
      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.num_labels
      )
      if labels is not None:
          labels = [torch.tensor(label) for label in labels]
          labels = torch.cat(labels, dim=0).to(logits)
          loss = self.loss_fnt(logits.float(), labels.float())
          output = (loss.to(sequence_output), output)
      return output
  
file_path: DeepKE/src/deepke/relation_extraction/document/model.py
imports: import torch
  import torch.nn
  from opt_einsum import contract
  from .losses import ATLoss
  import torch.nn.functional
  from .module import AttentionUNet
  from .prepro import process_long_input
label_desc: Use image node_id 7 for calling the DocREModel obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, labels, entity_pos, hts, instance_mask) and returns: output