class_docstr: Model wrapper for joint entity and relation extraction.
class_docstr_tok: ["Model","wrapper","for","joint","entity","and","relation","extraction","."]
code: def extract_gold_res_from_gold_annotation(
      self, tensor_example, stored_info=None
  ):
      output_ids = tensor_example["target_ids"]
      mapping = self.get_mapping_to_input_sequence(output_ids)
  
      ent_types, rel_types, ent_indices, rel_indices = (
          tensor_example["ent_types"],
          tensor_example["rel_types"],
          tensor_example["ent_indices"],
          tensor_example["rel_indices"],
      )
      subtoken_map = stored_info["subtoken_map"]
  
      entities, relations, start_ind = [], [], []
      entity_map = {}
      # reconstructing mention_indices and antecedent_indices
      for i in range(len(output_ids)):
          if output_ids[i] == self.mention_start_id:
              start_ind.append(i)
          if output_ids[i] == self.mention_end_id:
              entity = (
                  int(
                      subtoken_map[int(mapping[start_ind[-1]])]
                  ),  # no nested
                  int(subtoken_map[int(mapping[i])]),
                  int(ent_types[i]),
              )
              entities.append(entity)
  
              entity_map[i] = entity
              this_rel_types = rel_types[i].tolist()
              this_rel_ants = rel_indices[i].tolist()
  
              for _, (ant_tail, rel_type) in enumerate(
                  zip(this_rel_ants, this_rel_types)
              ):
                  if rel_type != -1:
                      relations.append(
                          (
                              entity_map[ant_tail][:2],
                              entity[:2],
                              int(rel_type),
                              entity_map[ant_tail][2],
                              entity[2],
                          )
                      )
      result_dict = {
          "gold_entities": entities,
          "gold_relations": relations,
      }
      return result_dict
  
file_path: DeepKE/src/deepke/triple_extraction/ASP/models/model_ere.py
imports: import sys
  import os
  import torch
  import torch.nn
  import logging
  from transformers import T5Tokenizer
  from .t5_ere import T5ERE
label_desc: Use image node_id 6 for calling the EREModel obj's underlying member method code with example usage: obj.extract_gold_res_from_gold_annotation(tensor_example, stored_info) and returns: result_dict