KGE.data_utils

Functions

calculate_data_size(X)

check_path_exist_and_create(path)

convert_kg_to_index(kg_data, ent2ind, rel2ind)

Convert the KG data into index

index_kg(kg_data)

Index the Knowledge Graph data.

set_tf_iterator(data, batch_size, shuffle[, ...])

train_test_split_no_unseen(X, test_size, seed)

Split KG data into train and test

Classes

myIter

tqdm

Decorate an iterable object, returning an iterator which acts exactly like the original iterable, but prints a dynamically updating progressbar every time a value is requested.

Class Inheritance Diagram

Inheritance diagram of KGE.data_utils.myIter
KGE.data_utils.convert_kg_to_index(kg_data, ent2ind, rel2ind)[source]

Convert the KG data into index

Parameters
  • kg_data (np.array) – KG data to be converted

  • ent2ind (dict) – dictionary that map entity to index

  • rel2ind (dict) – dictionary that map relation to index

Returns

indexed KG data

Return type

np.array

KGE.data_utils.index_kg(kg_data)[source]

Index the Knowledge Graph data.

Parameters

kg_data (np.array) – KG data to be indexed

Returns

metadata of KG <br> 'ent2ind': dictionary that map entity to index 'ind2ent': list that map index to entity 'rel2ind': dictionary that map relation to index 'ind2rel': list that map index to relation

Return type

dict

KGE.data_utils.train_test_split_no_unseen(X, test_size, seed)[source]

Split KG data into train and test

Split KG data into train and test, this function guarantees that the entities in test data are also present in the train data.

Parameters
  • X (np.array) – KG data to be splitted

  • test_size (int or float) – desired test size, if int, represents the absolute test size, if float, represents the relative proportion.

  • seed (int) – random seed

Returns

splitted train, test KG data

Return type

np.array, np.array