def load_from_hdf5(self, path):
"""load model in compressed sparse row format from hdf5 file
hdf5 file should contain row_ptr, col_ind and data array
Args:
path: path to the embeddings folder
"""
self.load_metadata(path)
f = tables.open_file(os.path.join(path, 'cooccurrence_csr.h5p'), 'r')
row_ptr = np.nan_to_num(f.root.row_ptr.read())
col_ind = np.nan_to_num(f.root.col_ind.read())
data = np.nan_to_num(f.root.data.read())
dim = row_ptr.shape[0] - 1
self.matrix = scipy.sparse.csr_matrix(
(data, col_ind, row_ptr), shape=(dim, dim), dtype=np.float32)
f.close()
self.vocabulary = Vocabulary_cooccurrence()
self.vocabulary.load(path)
self.name += os.path.basename(os.path.normpath(path))
评论列表
文章目录