Esempio n. 1
0
    def __init__(self, model_name, data_name, cv_runs, params_dict, logger,
                 eval_by_rel):
        dataset = DataSet(config.DATASET[data_name])
        self.train_triples, self.valid_triples, self.test_triples = dataset.load_data(
        )
        self.e2id, self.r2id = dataset.load_idx()

        self.model_name = model_name
        self.data_name = data_name
        self.cv_runs = cv_runs
        self.params_dict = params_dict
        self.hparams = AttrDict(params_dict)
        self.logger = logger
        self.n_entities = len(self.e2id)
        self.n_relations = len(self.r2id)
        if eval_by_rel:
            self.scorer = RelationScorer(self.train_triples,
                                         self.valid_triples, self.test_triples,
                                         self.n_relations)
        else:
            self.scorer = Scorer(self.train_triples, self.valid_triples,
                                 self.test_triples, self.n_entities)

        self.model = self._get_model()
        self.saver = tf.train.Saver(tf.global_variables())
        checkpoint_path = os.path.abspath(config.CHECKPOINT_PATH)
        if not os.path.exists(checkpoint_path):
            os.makedirs(checkpoint_path)
        self.checkpoint_prefix = os.path.join(checkpoint_path, self.__str__())
Esempio n. 2
0
    def __init__(self, model_name, data_name, cv_runs, params_dict, logger, eval_by_rel):
        dataset = DataSet(config.DATASET[data_name])
        self.train_triples, self.valid_triples, self.test_triples = dataset.load_data()
        self.e2id, self.r2id = dataset.load_idx()

        self.groundings = dataset.load_groundings() if "SoLE" in model_name else None
        self.model_name = model_name
        self.data_name = data_name
        self.cv_runs = cv_runs
        self.params_dict = params_dict
        self.hparams = AttrDict(params_dict)
        if "batch_size" not in self.hparams :
            if "batch_num" in self.hparams :
                self.hparams["batch_size"] = int(len(self.train_triples)/self.hparams["batch_num"])
            else:
                raise AttributeError("Need parameter batch_size or batch_num! (Check model_param_space.py)")

        self.logger = logger
        self.n_entities = len(self.e2id)
        self.n_relations = len(self.r2id)
        if eval_by_rel:
            self.scorer = RelationScorer(
                self.train_triples, self.valid_triples, self.test_triples, self.n_relations)
        else:
            self.scorer = Scorer(
                self.train_triples, self.valid_triples, self.test_triples, self.n_entities)

        self.model = self._get_model()
        self.saver = tf.train.Saver(tf.global_variables(), max_to_keep=1)
        checkpoint_path = os.path.abspath(config.CHECKPOINT_PATH + "/" + self.__str__() +
                                          ("_NNE_" if "NNE_enable" in self.hparams and self.hparams.NNE_enable == True else "_noNNE_") + data_name)
        if not os.path.exists(checkpoint_path):
            os.makedirs(checkpoint_path)
        self.checkpoint_prefix = os.path.join(checkpoint_path, self.__str__())

        print(self.hparams)