Exemplo n.º 1
0
X_sym, X_mask_sym, y_sym, y_mask_sym = add_datasets_to_graph(
    datasets_list, names_list, graph, list_of_test_values=datasets_list)

n_hid = 256
n_out = 8

h = location_attention_tanh_recurrent_layer(
    [X_sym], [y_sym], X_mask_sym, y_mask_sym, n_hid, graph, 'l1_att_rec',
    random_state=random_state)

X_hat = sigmoid_layer([h], graph, 'output', proj_dim=n_out,
                      random_state=random_state)
cost = binary_crossentropy(X_hat, X_sym).mean()
cost = masked_cost(cost, X_mask_sym).mean()
params, grads = get_params_and_grads(graph, cost)
opt = adadelta(params)
updates = opt.updates(params, grads)
fit_function = theano.function([X_sym, X_mask_sym, y_sym, y_mask_sym],
                               [cost], updates=updates)
valid_function = theano.function([X_sym, X_mask_sym, y_sym, y_mask_sym], [cost])

checkpoint_dict = {}
checkpoint_dict["fit_function"] = fit_function
checkpoint_dict["valid_function"] = valid_function
TL = TrainingLoop(fit_function, valid_function, train_itr, valid_itr,
                  checkpoint_dict=checkpoint_dict,
                  list_of_train_output_names=["train_cost"],
                  valid_output_name="valid_cost",
                  n_epochs=500,
                  optimizer_object=opt)
epoch_results = TL.run()
Exemplo n.º 2
0
l1 = tanh_layer([X_sym],
                graph,
                'l1',
                proj_dim=n_hid,
                random_state=random_state)
coeffs, mus, log_sigmas = log_gaussian_mixture_layer([l1],
                                                     graph,
                                                     'mdn',
                                                     proj_dim=1,
                                                     n_components=24,
                                                     random_state=random_state)
cost = log_gaussian_mixture_cost(coeffs, mus, log_sigmas, y_sym).mean()
params, grads = get_params_and_grads(graph, cost)

opt = adadelta(params)
updates = opt.updates(params, grads)

fit_function = theano.function([X_sym, y_sym], [cost], updates=updates)
cost_function = theano.function([X_sym, y_sym], [cost])
predict_function = theano.function([X_sym], [coeffs, mus, log_sigmas])

checkpoint_dict = create_checkpoint_dict(locals())

train_itr = minibatch_iterator([X, y], minibatch_size, axis=0)
valid_itr = minibatch_iterator([X, y], minibatch_size, axis=0)

next(train_itr)

TL = TrainingLoop(fit_function,
                  cost_function,