def dataset_from_file(filename):
"""Load a dataset from file.
Args:
filename (string): the name of the file from which extract the dataset
Returns:
tuple: the dataset (np.ndarray) and the ngrams (list of strings)
"""
loader = np.load(filename)
num_entries = loader['num_entries'][0]
sp_dataset = sparse.csr_matrix((loader['data'], loader['indices'], loader['indptr']),
shape = loader['shape'])
dataset = sp_dataset.toarray()
samp_entries, num_features = dataset.shape
return dataset.reshape(int(samp_entries / num_entries), num_entries, num_features), loader['ngrams']
评论列表
文章目录