示例#1
0
    def load_graph_data(self, data_dir):
        # Load indices {"concept_book_new": "1", "concept_lake_new": "1", ...}
        self.entity2id, self.id2entity = load_index(
            os.path.join(data_dir, "entity2id.txt"))
        print("Sanity check: {} entities loaded".format(len(self.entity2id)))
        self.type2id, self.id2type = load_index(
            os.path.join(data_dir, "type2id.txt"))
        print("Sanity check: {} types loaded".format(len(self.type2id)))
        with open(os.path.join(data_dir, "entity2typeid.pkl"), "rb") as f:
            self.entity2typeid = pickle.load(f)
        self.relation2id, self.id2relation = load_index(
            os.path.join(data_dir, "relation2id.txt"))
        print("Sanity check: {} relations loaded".format(len(
            self.relation2id)))

        # Load graph structures (not used for training embeddings)
        if self.args.model.startswith("point"):
            # Base graph structure used for training and test
            adj_list_path = os.path.join(data_dir, "adj_list.pkl")
            with open(adj_list_path, "rb") as f:
                self.adj_list = pickle.load(f)
            self.vectorize_action_space(data_dir)
示例#2
0
    def load_graph_data(self, data_dir):
        # Load indices
        self.entity2id, self.id2entity = load_index(
            os.path.join(data_dir, 'entity2id.txt'))
        print('Sanity check: {} entities loaded'.format(len(self.entity2id)))
        self.type2id, self.id2type = load_index(
            os.path.join(data_dir, 'type2id.txt'))
        print('Sanity check: {} types loaded'.format(len(self.type2id)))
        with open(os.path.join(data_dir, 'entity2typeid.pkl'), 'rb') as f:
            self.entity2typeid = pickle.load(f)
        self.relation2id, self.id2relation = load_index(
            os.path.join(data_dir, 'relation2id.txt'))
        print('Sanity check: {} relations loaded'.format(len(
            self.relation2id)))

        # Load graph structures
        if self.args.model.startswith('point'):
            # Base graph structure used for training and test
            adj_list_path = os.path.join(data_dir, 'adj_list.pkl')
            with open(adj_list_path, 'rb') as f:
                self.adj_list = pickle.load(f)
            self.vectorize_action_space(data_dir)
示例#3
0
    def load_graph_data(self, data_dir):
        # Load indices
        self.entity2id, self.id2entity = load_index(
            os.path.join(data_dir, "entity2id.txt"))
        print("Sanity check: {} entities loaded".format(len(self.entity2id)))
        self.type2id, self.id2type = load_index(
            os.path.join(data_dir, "type2id.txt"))
        print("Sanity check: {} types loaded".format(len(self.type2id)))
        with open(os.path.join(data_dir, "entity2typeid.pkl"), "rb") as f:
            self.entity2typeid = pickle.load(f)
        self.relation2id, self.id2relation = load_index(
            os.path.join(data_dir, "relation2id.txt"))
        print("Sanity check: {} relations loaded".format(len(
            self.relation2id)))

        # Load graph structures
        if self.args.model.startswith("point"):
            # Base graph structure used for training and test
            adj_list_path = os.path.join(data_dir, "adj_list.pkl")
            with open(adj_list_path, "rb") as f:
                self.e1_to_r_to_e2 = pickle.load(f)
            self.preprocess_knowledge_graph(data_dir)