Construct sets from KB. A natural set is defined as a set of entities that share the same property, e.g. movies directed by Nolan, or actors appear in Inception. Args: train_split: percentage of data for training Returns: a list of train sets and test sets
(
self, train_split)
| 269 | self.construct_query2box(name) |
| 270 | |
| 271 | def construct_membership( |
| 272 | self, train_split): |
| 273 | """Construct sets from KB. |
| 274 | |
| 275 | A natural set is defined as a set of entities that share the same |
| 276 | property, e.g. movies directed by Nolan, or actors appear in Inception. |
| 277 | |
| 278 | Args: |
| 279 | train_split: percentage of data for training |
| 280 | |
| 281 | Returns: |
| 282 | a list of train sets and test sets |
| 283 | """ |
| 284 | train_data = list() |
| 285 | test_data = list() |
| 286 | |
| 287 | for unused_subj_id, subj in self.id2entity.items(): |
| 288 | all_objs = set() |
| 289 | for _, objs in self.kb[subj].items(): |
| 290 | all_objs.update(objs) |
| 291 | # Group entities by graph structure. Entities within distance one |
| 292 | # are considered as an element in the set. |
| 293 | if len(all_objs) > 1: |
| 294 | one_data = all_objs |
| 295 | else: |
| 296 | continue |
| 297 | |
| 298 | if random.random() < train_split: |
| 299 | train_data.append(one_data) |
| 300 | else: |
| 301 | test_data.append(one_data) |
| 302 | |
| 303 | tf.logging.info('set examples: %d train, %d test', len(train_data), |
| 304 | len(test_data)) |
| 305 | return train_data, test_data |
| 306 | |
| 307 | def construct_set_pairs( |
| 308 | self, train_split): |