def construct_set_pairs(
      self, train_split):
    """Construct pairs of sets from KB with at least one entity in common.

    Args:
      train_split: percentage of data for training

    Returns:
      a list of train pairs and test pairs
    """
    random.seed(SEED)
    subj2objs = dict()
    for subj, facts in self.kb.items():
      all_objs = set()
      for unused_rel, objs in facts.items():
        all_objs.update(objs)
      subj2objs[subj] = all_objs

    train_pairs = list()
    test_pairs = list()
    for target, objs in subj2objs.items():
      if len(objs) <= 1:
        continue
      # Find candidate sets which have at least 2 entities.
      candidate_sets = list()
      for obj in objs:
        for unused_rel, subjs in self.kb[obj].items():
          if len(subjs) > 1 and target in subjs:
            candidate_sets.append(subjs)
      # Randomly pick some pair of sets.
      num_pairs = int(len(candidate_sets) / 2)
      for i in range(num_pairs):
        set1 = candidate_sets[2 * i]
        set2 = candidate_sets[2 * i + 1]
        if random.random() < train_split:
          train_pairs.append((set1, set2))
        else:
          test_pairs.append((set1, set2))
    tf.logging.info(
        'set_pair (intersection & union) examples: %d train, %d test',
        len(train_pairs), len(test_pairs))

    return train_pairs, test_pairs
Construct pairs of sets from KB with at least one entity in common.

    Args:
      train_split: percentage of data for training

    Returns:
      a list of train pairs and test pairs
    
language/emql/data_loader.py