def save_pkl_files(dsm_prefix, dsm, save_in_one_file=False):
"""
Save the space to separate pkl files.
:param dsm_prefix:
:param dsm:
"""
# Save in a single file (for small spaces)
if save_in_one_file:
io_utils.save(dsm, dsm_prefix + '.pkl')
# Save in multiple files: npz for the matrix and pkl for the other data members of Space
else:
mat = coo_matrix(dsm.cooccurrence_matrix.get_mat())
np.savez_compressed(dsm_prefix + 'cooc.npz', data=mat.data, row=mat.row, col=mat.col, shape=mat.shape)
with open(dsm_prefix + '_row2id.pkl', 'wb') as f_out:
pickle.dump(dsm._row2id, f_out, 2)
with open(dsm_prefix + '_id2row.pkl', 'wb') as f_out:
pickle.dump(dsm._id2row, f_out, 2)
with open(dsm_prefix + '_column2id.pkl', 'wb') as f_out:
pickle.dump(dsm._column2id, f_out, 2)
with open(dsm_prefix + '_id2column.pkl', 'wb') as f_out:
pickle.dump(dsm._id2column, f_out, 2)
评论列表
文章目录