예제 #1
0
def main_for_args(arg_path, dataset, division):
    t = time.time()
    args = load_args(arg_path)
    args.training_data = args.training_data + dataset + "/"
    args.dataset_division = division
    print(args.embedding_module)
    print(args)
    remove_unlinked = False
    if args.embedding_module == "RSN4EA":
        remove_unlinked = True
    kgs = read_kgs_from_folder(
        args.training_data,
        args.dataset_division,
        args.alignment_module,
        args.ordered,
        remove_unlinked=remove_unlinked,
    )
    import tensorflow as tf

    tf.keras.backend.clear_session()
    model = get_model(args.embedding_module)()
    model.set_args(args)
    model.set_kgs(kgs)
    model.init()
    model.run()
    model.test()
    model.save()
    print("Total run time = {:.3f} s.".format(time.time() - t))
예제 #2
0
def loaded_kgs():
    path = "data/OpenEA/D_W_15K_V1/"
    if not os.path.exists(path):
        path = os.path.join("..", path)
    return read_kgs_from_folder(
        path, "721_5fold/1/", "mapping", True, remove_unlinked=False,
    )
예제 #3
0
 def __init__(self, args):
     self.args = args
     self.session = load_session()
     self.kgs = read_kgs_from_folder(args.training_data,
                                     args.dataset_division,
                                     args.alignment_module, False)
     self.entities = self.kgs.kg1.entities_set | self.kgs.kg2.entities_set
     self.word2vec_path = args.word2vec_path
     self.entity_local_name_dict = read_local_name(
         args.training_data, set(self.kgs.kg1.entities_id_dict.keys()),
         set(self.kgs.kg2.entities_id_dict.keys()))
     self._generate_literal_vectors()
     self._generate_name_vectors_mat()
     self._generate_attribute_value_vectors()
예제 #4
0
 def __init__(self, data_folder: str, division: str, args_path: str):
     args = load_args(args_path)
     self._data_folder = data_folder
     self.download_and_unzip()
     self._kgs = read_kgs_from_folder(data_folder, division,
                                      args.alignment_module, args.ordered)
     train_links = [(e[0], e[1], 1) for e in self._kgs.train_links]
     valid_links = [(e[0], e[1], 1) for e in self._kgs.valid_links]
     test_links = [(e[0], e[1], 1) for e in self._kgs.test_links]
     super().__init__(
         kg1=self._kgs.kg1,
         kg2=self._kgs.kg2,
         rnd=random.Random(),
         labelled_pairs=train_links,
         labelled_val_pairs=valid_links,
         labelled_test_pairs=test_links,
     )
     self._name = data_folder.split("/")[-2] + "/" + division[:-1]
예제 #5
0
    def __init__(self,
                 data_folder: str,
                 division: str,
                 args_path: str,
                 random_seed=0):
        args = load_args(args_path)
        self._data_folder = data_folder
        self.download_and_unzip()
        self._kgs = read_kgs_from_folder(data_folder, division,
                                         args.alignment_module, args.ordered)

        train_links = [(e[0], e[1], 1) for e in self._kgs.train_links]
        valid_links = [(e[0], e[1], 1) for e in self._kgs.valid_links]
        test_links = [(e[0], e[1], 1) for e in self._kgs.test_links]
        super().__init__(
            kg1=self._kgs.kg1,
            kg2=self._kgs.kg2,
            rnd=random.Random(random_seed),
            labelled_pairs=train_links + valid_links + test_links,
            # throw them together because of possible inbalance
            # due to removal of inner links
        )
        self._name = data_folder.split("/")[-2] + "/" + division[:-1]
예제 #6
0
 args.dataset_division = sys.argv[
     3]  # This is the fold used among the k (5) available.
 if len(sys.argv) < 5:
     args.gpu = "0"
 else:
     if sys.argv[4] == "CPU":
         args.gpu = None
     else:
         args.gpu = sys.argv[4]
 print(args.embedding_module)
 print(args)
 remove_unlinked = False
 if args.embedding_module == "RSN4EA":
     remove_unlinked = True
 # load the kgs and put them in a class (see inner classes for more details)
 kgs = read_kgs_from_folder(args.training_data,
                            args.dataset_division,
                            args.alignment_module,
                            args.ordered,
                            args.extra_entities_percentage_valid,
                            remove_unlinked=remove_unlinked)
 model = get_model(
     args.embedding_module)()  # Get the current model class from args
 model.set_args(args)
 model.set_kgs(kgs)
 model.init()
 model.run()
 model.test()
 model.test_new()
 model.save()
 print("Total run time = {:.3f} s.".format(time.time() - t))
예제 #7
0
    args.alignment_module = sys.argv[9]
    args.rel_inp_dropout = float(sys.argv[10])
    args.rel_hid_dropout = float(sys.argv[11])
    args.rel_hidden_dim = float(sys.argv[12])
    args.train_module = sys.argv[13]
    args.exist_attr = False
    print("load arguments:", vars(args))

    remove_unlinked = False
    if args.embedding_module == "RSN4EA":
        remove_unlinked = True
    kgs = read_kgs_from_folder(args.training_data,
                               args.dataset_division,
                               args.alignment_module,
                               args.ordered,
                               remove_unlinked=remove_unlinked,
                               exist_attr=args.exist_attr,
                               train_kg=args.train_kg)
    model = get_model(args.embedding_module)()
    model.set_args(args)
    model.set_kgs(kgs)
    model.init()
    print("Model Parameters:")
    for v in tf.compat.v1.trainable_variables():
        print(v)
    model.run()
    model.eval_test()
    model.save()

    print("Total run time = {:.3f} s.".format(time.time() - t))
예제 #8
0
    RSN4EA = RSN4EA
    SEA = SEA

    MTransE = MTransE
    IPTransE = IPTransE
    Attr2Vec = Attr2Vec
    JAPE = JAPE
    AlignE = AlignE
    BootEA = BootEA
    GCN_Align = GCN_Align
    GMNN = GMNN
    KDCoE = KDCoE
    RDGCN = RDGCN
    AliNet = AliNet


def get_model(model_name):
    return getattr(ModelFamily, model_name)


if __name__ == '__main__':
    kgs = read_kgs_from_folder(args.training_data, args.dataset_division,
                               args.alignment_module, args.ordered)
    model = get_model(args.embedding_module)()
    model.set_args(args)
    model.set_kgs(kgs)
    model.init()
    model.run()
    model.test()
    model.save()