コード例 #1
0
dataset = sio.loadmat('./data/WS.mat')
train_data = np.asarray(dataset['doc'].todense()[:, dataset['train_idx'][0] -
                                                 1])[:, ::10].astype(int)
test_data = np.asarray(dataset['doc'].todense()[:, dataset['test_idx'][0] -
                                                1])[:, ::5].astype(int)
train_label = dataset['labels'][dataset['train_idx'][0] - 1][::10, :]
test_label = dataset['labels'][dataset['test_idx'][0] - 1][::5, :]

# params of model
T = 3  # vertical layers
S = 3  # sub topics
K = [100] * T  # topics in each layers

# create the model and deploy it on gpu or cpu
model = WEDTM(K, 'gpu')
model.initial(
    dataset['doc']
)  # use the shape of train_data to initialize the params of model
train_local_params = model.train(dataset['embeddings'], S, 300, train_data)
train_local_params = model.test(dataset['embeddings'], S, 300, train_data)
test_local_params = model.test(dataset['embeddings'], S, 300, test_data)

# evaluate the model with classification accuracy
# the demo accuracy can achieve
results = ACC(train_local_params.Theta, test_local_params.Theta, train_label,
              test_label, 'SVM')

# save the model after training
model.save()
# model.load('./save_models/WEDTM.npy')
コード例 #2
0
ファイル: CPGBN_Demo.py プロジェクト: BoChenGroup/pydpm
# create the model and deploy it on gpu or cpu
model = CPGBN([200, 100, 50], 'gpu')
# mode 1, dense input
model.initial(
    [batch_file_index_tr, batch_rows_tr, batch_cols_tr, batch_value_tr], [
        len(data_train_list) - delete_count, DATA['Vab_Size'],
        np.max(batch_len_tr)
    ])  # use the shape of train_data to initialize the params of model
train_local_params = model.train(
    100, [batch_file_index_tr, batch_rows_tr, batch_cols_tr, batch_value_tr], [
        len(data_train_list) - delete_count, DATA['Vab_Size'],
        np.max(batch_len_tr)
    ])
train_local_params = model.test(
    100, [batch_file_index_tr, batch_rows_tr, batch_cols_tr, batch_value_tr], [
        len(data_train_list) - delete_count, DATA['Vab_Size'],
        np.max(batch_len_tr)
    ])
test_local_params = model.test(
    100, [batch_file_index_te, batch_rows_te, batch_cols_te, batch_value_te], [
        len(data_test_list) - delete_count, DATA['Vab_Size'],
        np.max(batch_len_te)
    ])

train_theta = np.sum(np.sum(train_local_params.W_nk, axis=3), axis=2).T
test_theta = np.sum(np.sum(test_local_params.W_nk, axis=3), axis=2).T

# Score of test dataset's Theta: 0.682
results = ACC(train_theta, test_theta, batch_label_tr, batch_label_te, 'SVM')
model.save()