(class_splits, spanning_leaves, valid_test_roots)
return split_leaves, split_roots
Gets leaf and root Synsets from different copies of the graph.

  In particular, a new copy is created for each split. For all three splits, the
  leaf Synsets of the corresponding copy that correspond to split classes are
  returned. For the validation and test graphs, the corresponding root Synsets
  are returned as well from the new copies. These will have the same WordNet id
  and name as those in valid_test_roots but are nodes from the copy of the graph
  instead of the original one.

  Args:
    class_splits: a dict whose keys are 'train', 'valid' and 'test' and whose
      value for a given key is the set of WordNet id's of the classes that are
      assigned to the corresponding split.
    spanning_leaves: A dict mapping each Synset to the leaf Synsets that are
      reachable from it.
    valid_test_roots: A dict whose keys should be 'valid' and 'test' and whose
      value for a given key is a Synset that spans all and only the leaves that
      will desirably be assigned to the corresponding split.

  Returns:
    a dict mapping each of 'train', 'valid' and 'test' to the set of Synsets (of
    the respective copy of the graph) corresponding to the classes that are
    assigned to that split.

  Raises:
    ValueError: invalid keys for valid_test_roots, or same synset provided as
      the root of both valid and test.
Gets leaf and root Synsets from different copies of the graph.
Gets leaf and root Synsets from different copies of the graph .
def init_split_subgraphs(class_splits, spanning_leaves, valid_test_roots):
  """Gets leaf and root Synsets from different copies of the graph.

  In particular, a new copy is created for each split. For all three splits, the
  leaf Synsets of the corresponding copy that correspond to split classes are
  returned. For the validation and test graphs, the corresponding root Synsets
  are returned as well from the new copies. These will have the same WordNet id
  and name as those in valid_test_roots but are nodes from the copy of the graph
  instead of the original one.

  Args:
    class_splits: a dict whose keys are 'train', 'valid' and 'test' and whose
      value for a given key is the set of WordNet id's of the classes that are
      assigned to the corresponding split.
    spanning_leaves: A dict mapping each Synset to the leaf Synsets that are
      reachable from it.
    valid_test_roots: A dict whose keys should be 'valid' and 'test' and whose
      value for a given key is a Synset that spans all and only the leaves that
      will desirably be assigned to the corresponding split.

  Returns:
    a dict mapping each of 'train', 'valid' and 'test' to the set of Synsets (of
    the respective copy of the graph) corresponding to the classes that are
    assigned to that split.

  Raises:
    ValueError: invalid keys for valid_test_roots, or same synset provided as
      the root of both valid and test.
  """
  # Get the wn_id's of the train, valid and test classes.
  train_wn_ids = class_splits['train']
  valid_wn_ids = class_splits['valid']
  test_wn_ids = class_splits['test']

  valid_root_wn_id = valid_test_roots['valid'].wn_id
  test_root_wn_id = valid_test_roots['test'].wn_id

  # Get 3 full copies of the graph that will be modified downstream.
  graph_copy_train, _ = copy_graph(spanning_leaves.keys())
  graph_copy_valid, valid_root = copy_graph(spanning_leaves.keys(),
                                            valid_root_wn_id)
  graph_copy_test, test_root = copy_graph(spanning_leaves.keys(),
                                          test_root_wn_id)

  # Get the nodes of each copy that correspond to the splits' assigned classes.
  train_classes = set([s for s in graph_copy_train if s.wn_id in train_wn_ids])
  valid_classes = set([s for s in graph_copy_valid if s.wn_id in valid_wn_ids])
  test_classes = set([s for s in graph_copy_test if s.wn_id in test_wn_ids])
  split_leaves = {
      'train': train_classes,
      'valid': valid_classes,
      'test': test_classes
  }
  split_roots = {'valid': valid_root, 'test': test_root}
  return split_leaves, split_roots
def init_split_subgraphs ( class_splits , spanning_leaves , valid_test_roots ) : # Get the wn_id's of the train, valid and test classes. train_wn_ids = class_splits [ 'train' ] valid_wn_ids = class_splits [ 'valid' ] test_wn_ids = class_splits [ 'test' ] valid_root_wn_id = valid_test_roots [ 'valid' ] . wn_id test_root_wn_id = valid_test_roots [ 'test' ] . wn_id # Get 3 full copies of the graph that will be modified downstream. graph_copy_train , _ = copy_graph ( spanning_leaves . keys ( ) ) graph_copy_valid , valid_root = copy_graph ( spanning_leaves . keys ( ) , valid_root_wn_id ) graph_copy_test , test_root = copy_graph ( spanning_leaves . keys ( ) , test_root_wn_id ) # Get the nodes of each copy that correspond to the splits' assigned classes. train_classes = set ( [ s for s in graph_copy_train if s . wn_id in train_wn_ids ] ) valid_classes = set ( [ s for s in graph_copy_valid if s . wn_id in valid_wn_ids ] ) test_classes = set ( [ s for s in graph_copy_test if s . wn_id in test_wn_ids ] ) split_leaves = { 'train' : train_classes , 'valid' : valid_classes , 'test' : test_classes } split_roots = { 'valid' : valid_root , 'test' : test_root } return split_leaves , split_roots