code: def negative_sample(self, record, task):
      (
          positive_type,
          positive_role,
          positive_type_role,
      ) = get_positive_type_role(record, task)
      negative = list()
      if task == "RE":
          negative = self.role_list - positive_role  # 负样本
          if self.negative > 0:  # <0, 是采样所有的负样本
              negative = random.sample(self.role_list, self.negative)
          for it in negative:
              if it not in positive_role:
                  record.append(
                      {"head": "", "relation": it, "tail": ""}
                  )
      elif task == "NER":
          negative = self.type_list - positive_type
          if self.negative > 0:  # <0, 是采样所有的负样本
              negative = random.sample(self.type_list, self.negative)
          for it in negative:
              if it not in positive_type:
                  record.append({"entity": "", "entity_type": it})
      elif task == "EE":
          negative_type = self.type_list - positive_type
          negative_type_role = defaultdict(set)
          if self.negative > 0:
              for key, value in positive_type_role.items():
                  negative_role = self.type_role_dict[key] - value
                  if len(negative_role) > 0:
                      negative_type_role[key] = negative_role
              for event in record:
                  if event["event_type"] in negative_type_role:
                      num_t = min(
                          len(self.type_role_dict[event["event_type"]]),
                          self.negative,
                      )
                      num_t = random.randint(1, num_t)
                      negative_role = random.sample(
                          self.type_role_dict[event["event_type"]],
                          num_t,
                      )
                      for it in negative_role:
                          if (
                              it
                              not in positive_type_role[
                                  event["event_type"]
                              ]
                          ):
                              event["arguments"].append(
                                  {"argument": "", "role": it}
                              )
                              positive_type_role[
                                  event["event_type"]
                              ].add(it)
              negative_type = random.sample(
                  self.type_list, self.negative
              )
              for it in negative_type:
                  if it not in positive_type:
                      record.append(
                          {
                              "event_trigger": "",
                              "event_type": it,
                              "arguments": [
                                  {"argument": "", "role": iit}
                                  for iit in self.type_role_dict[it]
                              ],
                          }
                      )
          else:  # <0, 是采样所有的负样本
              for event in record:
                  neg_role = (
                      self.type_role_dict[event["event_type"]]
                      - positive_type_role[event["event_type"]]
                  )
                  if len(neg_role) > 0:
                      for it in neg_role:
                          event["arguments"].append(
                              {"argument": "", "role": it}
                          )
              neg_type = self.type_list - positive_type
              for it in neg_type:
                  record.append(
                      {
                          "event_trigger": "",
                          "event_type": it,
                          "arguments": [
                              {"argument": "", "role": iit}
                              for iit in self.type_role_dict[it]
                          ],
                      }
                  )
      elif task == "EEA":
          negative_type = self.type_list - positive_type
          negative_type_role = defaultdict(set)
          if self.negative > 0:
              for key, value in positive_type_role.items():
                  negative_role = self.type_role_dict[key] - value
                  if len(negative_role) > 0:
                      negative_type_role[key] = negative_role
              for event in record:
                  if event["event_type"] in negative_type_role:
                      num_t = min(
                          len(self.type_role_dict[event["event_type"]]),
                          self.negative,
                      )
                      num_t = random.randint(1, num_t)
                      negative_role = random.sample(
                          self.type_role_dict[event["event_type"]],
                          num_t,
                      )
                      for it in negative_role:
                          if (
                              it
                              not in positive_type_role[
                                  event["event_type"]
                              ]
                          ):
                              event["arguments"].append(
                                  {"argument": "", "role": it}
                              )
                              positive_type_role[
                                  event["event_type"]
                              ].add(it)
          else:  # <0, 是采样所有的负样本
              for event in record:
                  neg_role = (
                      self.type_role_dict[event["event_type"]]
                      - positive_type_role[event["event_type"]]
                  )
                  if len(neg_role) > 0:
                      for it in neg_role:
                          event["arguments"].append(
                              {"argument": "", "role": it}
                          )
      elif task == "EET":
          negative = self.type_list - positive_type
          if self.negative > 0:
              negative = random.sample(self.type_list, self.negative)
          for it in negative:  # <0, 是采样所有的负样本
              if it not in positive_type:
                  record.append({"event_trigger": "", "event_type": it})
      return record
  
file_path: DeepKE/example/llm/InstructKGC/kg2instruction/convert/sampler.py
imports: import json
  import os
  from collections import defaultdict
  import random
label_desc: Use image node_id 3 for calling the Sampler obj's underlying member method code with example usage: obj.negative_sample(record, task) and returns: record