code: def get_hrt(self, sequence_output, attention, entity_pos, hts):
      offset = (
          1
          if self.config.transformer_type in ["bert", "roberta"]
          else 0
      )
      bs, h, _, c = attention.size()
      # ne = max([len(x) for x in entity_pos])  # 本次bs中的最大实体数
  
      hss, tss, rss = [], [], []
      entity_es = []
      entity_as = []
      for i in range(len(entity_pos)):
          entity_embs, entity_atts = [], []
          for entity_num, e in enumerate(entity_pos[i]):
              if len(e) > 1:
                  e_emb, e_att = [], []
                  for start, end in e:
                      if start + offset < c:
                          # In case the entity mention is truncated due to limited max seq length.
                          e_emb.append(
                              sequence_output[i, start + offset]
                          )
                          e_att.append(attention[i, :, start + offset])
                  if len(e_emb) > 0:
                      e_emb = torch.logsumexp(
                          torch.stack(e_emb, dim=0), dim=0
                      )
                      e_att = torch.stack(e_att, dim=0).mean(0)
                  else:
                      e_emb = torch.zeros(self.config.hidden_size).to(
                          sequence_output
                      )
                      e_att = torch.zeros(h, c).to(attention)
              else:
                  start, end = e[0]
                  if start + offset < c:
                      e_emb = sequence_output[i, start + offset]
                      e_att = attention[i, :, start + offset]
                  else:
                      e_emb = torch.zeros(self.config.hidden_size).to(
                          sequence_output
                      )
                      e_att = torch.zeros(h, c).to(attention)
              entity_embs.append(e_emb)
              entity_atts.append(e_att)
          for _ in range(self.min_height - entity_num - 1):
              entity_atts.append(e_att)
  
          entity_embs = torch.stack(entity_embs, dim=0)  # [n_e, d]
          entity_atts = torch.stack(
              entity_atts, dim=0
          )  # [n_e, h, seq_len]
  
          entity_es.append(entity_embs)
          entity_as.append(entity_atts)
          ht_i = torch.LongTensor(hts[i]).to(sequence_output.device)
          hs = torch.index_select(entity_embs, 0, ht_i[:, 0])
          ts = torch.index_select(entity_embs, 0, ht_i[:, 1])
  
          hss.append(hs)
          tss.append(ts)
      hss = torch.cat(hss, dim=0)
      tss = torch.cat(tss, dim=0)
      return hss, tss, entity_es, entity_as
  
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 3 for calling the DocREModel obj's underlying member method code with example usage: obj.get_hrt(sequence_output, attention, entity_pos, hts) and returns: hss,  tss,  entity_es,  entity_as