code: def attach_entities(groups, entities):
      """
      Attaches a documents entities to the documents groups
  
      :param groups: A list of groups
      :param entities: A list of entities
      :return: A copy of the groups param with an additional "entities" key added
      to each group containing all entities that appear within the group
      """
      # Copy so we don't modify input
      groups = deepcopy(groups)
      for group in groups:
          group["entities"] = []
          for entity in entities:
              if entity_in_group(entity, group):
                  group["entities"].append(entity)
      return groups
  
imports: from copy import deepcopy
  from collections import namedtuple
  import numpy
  from scipy.optimize import linear_sum_assignment
  from finetune.util.metrics import _convert_to_token_list, _get_unique_classes, calc_precision, calc_recall, calc_f1
label_desc: Use image node_id 19 for calling a global function with example usage: attach_entities(groups, entities) and returns: groups