Beispiel #1
0
m_y_hat = output.fprop([m_h1_out], params)

m_cost = NllMulInd(y, m_y_hat).mean()
m_err = error(predict(m_y_hat), y)
m_cost.name = 'cross_entropy'
m_err.name = 'error_rate'

monitor_fn = theano.function([x, y], [m_cost, m_err])

model.inputs = [x, y]
model.params = params
model.nodes = nodes

# Define your optimizer: Momentum (Nesterov), RMSProp, Adam
optimizer = RMSProp(
    #lr=0.01
    lr=0.005)

extension = [
    GradientClipping(batch_size=batch_size, check_nan=1),
    EpochCount(500),
    Monitoring(freq=1000,
               ddout=[m_cost, m_err],
               data=[
                   Iterator(train_data, batch_size),
                   Iterator(valid_data, batch_size)
               ],
               monitor_fn=monitor_fn),
    Picklize(freq=100000, path=save_path),
    WeightNorm(keys='W')
]
Beispiel #2
0
# Build the Theano computational graph
h1_out = h1.fprop([x])
y_hat = output.fprop([h1_out])

# Compute the cost
cost = NllMulInd(y, y_hat).mean()
err = error(predict(y_hat), y)
cost.name = 'cross_entropy'
err.name = 'error_rate'

model.inputs = [x, y]
model._params = params
model.nodes = nodes

# Define your optimizer: Momentum (Nesterov), RMSProp, Adam
optimizer = RMSProp(lr=0.001)

extension = [
    GradientClipping(),
    EpochCount(40),
    Monitoring(freq=100,
               ddout=[cost, err],
               data=[
                   Iterator(train_data, batch_size),
                   Iterator(valid_data, batch_size)
               ]),
    Picklize(freq=200, path=save_path)
]

mainloop = Training(name='toy_mnist',
                    data=Iterator(train_data, batch_size),
Beispiel #3
0
ts, _, _ = y_hat_temp.shape
y_hat_in = y_hat_temp.reshape((ts * batch_size, -1))
y_in = y.reshape((ts * batch_size, -1))
cost = NllBin(y_in, y_hat_in)
cost_temp = cost.reshape((ts, batch_size))
cost = cost_temp * mask
nll = cost.sum() / mask.sum()
cost = cost.sum(axis=0).mean()
cost.name = 'cost'
nll.name = 'nll'

model.inputs = [x, y, mask]
model._params = params
model.nodes = nodes

optimizer = RMSProp(lr=0.0001, mom=0.95)

extension = [
    GradientClipping(batch_size=batch_size),
    EpochCount(100),
    Monitoring(freq=10,
               ddout=[cost, nll],
               data=[Iterator(valid_data, batch_size)]),
    Picklize(freq=10, path=save_path)
]

mainloop = Training(name='toy_music',
                    data=Iterator(train_data, batch_size),
                    model=model,
                    optimizer=optimizer,
                    cost=cost,