(spanning_leaves, valid_test_roots=None, **kwargs)
return split_classes, valid_test_roots
Gets the assignment of classes (graph leaves) to splits.

  First, if valid_test_roots is not provided, roots for the validation and test
  sub-graphs are proposed by calling propose_valid_test_roots.

  Then, all classes spanned by the valid root Synset will be assigned to the
  validation set, all classes spanned by test root Synset will be assigned to
  the test split, and all remaining classes to the training split. When there
  are leaves spanned by both validation and test, they are assigned to one of
  the two randomly (roughly equally).

  Args:
    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.
    **kwargs: Keyword arguments for the root proposer that is used if
      valid_test_roots is None.

  Returns:
    split_classes: A dict that maps each of 'train', 'valid' and 'test' to the
      set of WordNet id's of the classes for the corresponding split.
    valid_test_roots: A dict of the same form as the corresponding optional
      argument.

  Raises:
    ValueError: when the provided valid_test_roots are invalid.
Gets the assignment of classes (graph leaves) to splits.
Gets the assignment of classes ( graph leaves ) to splits .
def get_class_splits(spanning_leaves, valid_test_roots=None, **kwargs):
  """Gets the assignment of classes (graph leaves) to splits.

  First, if valid_test_roots is not provided, roots for the validation and test
  sub-graphs are proposed by calling propose_valid_test_roots.

  Then, all classes spanned by the valid root Synset will be assigned to the
  validation set, all classes spanned by test root Synset will be assigned to
  the test split, and all remaining classes to the training split. When there
  are leaves spanned by both validation and test, they are assigned to one of
  the two randomly (roughly equally).

  Args:
    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.
    **kwargs: Keyword arguments for the root proposer that is used if
      valid_test_roots is None.

  Returns:
    split_classes: A dict that maps each of 'train', 'valid' and 'test' to the
      set of WordNet id's of the classes for the corresponding split.
    valid_test_roots: A dict of the same form as the corresponding optional
      argument.

  Raises:
    ValueError: when the provided valid_test_roots are invalid.
  """
  if valid_test_roots is not None:
    if valid_test_roots['valid'] is None or valid_test_roots['test'] is None:
      raise ValueError('A root cannot be None.')

  if valid_test_roots is None:
    valid_test_roots = propose_valid_test_roots(spanning_leaves, **kwargs)

  valid_root, test_root = valid_test_roots['valid'], valid_test_roots['test']

  # The WordNet id's of the validation and test classes
  valid_wn_ids = set([s.wn_id for s in spanning_leaves[valid_root]])
  test_wn_ids = set([s.wn_id for s in spanning_leaves[test_root]])

  # There may be overlap between the spanning leaves of the chosen roots for
  # the validation and test subtrees, which would cause overlap between the
  # classes assigned to these splits. This is addressed below by randomly
  # assigning each overlapping leaf to either validation or test classes
  # (roughly equally).
  overlap = [s for s in valid_wn_ids if s in test_wn_ids]
  logging.info('Size of overlap: %d leaves', len(overlap))
  assign_to_valid = True
  for s in overlap:
    if assign_to_valid:
      test_wn_ids.remove(s)
    else:
      valid_wn_ids.remove(s)
    assign_to_valid = not assign_to_valid

  # Training classes are all the remaining ones that are not already assigned
  leaves = get_leaves(spanning_leaves.keys())
  train_wn_ids = set([
      s.wn_id
      for s in leaves
      if s.wn_id not in valid_wn_ids and s.wn_id not in test_wn_ids
  ])

  split_classes = {
      'train': train_wn_ids,
      'valid': valid_wn_ids,
      'test': test_wn_ids
  }
  return split_classes, valid_test_roots
def get_class_splits ( spanning_leaves , valid_test_roots = None , * * kwargs ) : if valid_test_roots is not None : if valid_test_roots [ 'valid' ] is None or valid_test_roots [ 'test' ] is None : raise ValueError ( 'A root cannot be None.' ) if valid_test_roots is None : valid_test_roots = propose_valid_test_roots ( spanning_leaves , * * kwargs ) valid_root , test_root = valid_test_roots [ 'valid' ] , valid_test_roots [ 'test' ] # The WordNet id's of the validation and test classes valid_wn_ids = set ( [ s . wn_id for s in spanning_leaves [ valid_root ] ] ) test_wn_ids = set ( [ s . wn_id for s in spanning_leaves [ test_root ] ] ) # There may be overlap between the spanning leaves of the chosen roots for # the validation and test subtrees, which would cause overlap between the # classes assigned to these splits. This is addressed below by randomly # assigning each overlapping leaf to either validation or test classes # (roughly equally). overlap = [ s for s in valid_wn_ids if s in test_wn_ids ] logging . info ( 'Size of overlap: %d leaves' , len ( overlap ) ) assign_to_valid = True for s in overlap : if assign_to_valid : test_wn_ids . remove ( s ) else : valid_wn_ids . remove ( s ) assign_to_valid = not assign_to_valid # Training classes are all the remaining ones that are not already assigned leaves = get_leaves ( spanning_leaves . keys ( ) ) train_wn_ids = set ( [ s . wn_id for s in leaves if s . wn_id not in valid_wn_ids and s . wn_id not in test_wn_ids ] ) split_classes = { 'train' : train_wn_ids , 'valid' : valid_wn_ids , 'test' : test_wn_ids } return split_classes , valid_test_roots