예제 #1
0
        batch_size=64
    )

    cost = rnnmodel.get_cost(X_v, L_v, Y_v)
    out = rnnmodel.get_output(X_v, L_v)

    logger.info('Initial validation cost: %s', np.mean(cost))
    min_cost = cost
    last_save = 0
    for i in range(100000):
        tick = time.clock()
        X, L, Y = iterator.gen_batch(
            split='train',
            batch_size=64
        )
        tock = time.clock()
        _ = rnnmodel.train_on_batch(X, L, Y)
        if (i+1) % 100 == 0:
            cost = rnnmodel.get_cost(X_v, L_v, Y_v)
            logger.info('Validation cost after  %s batches: %s', i, cost)
            if cost < min_cost:
                min_cost = cost
                rnnmodel.save('/new_models/SoSmodel')
                last_save = 0
                logger.info('Saving model at validation cost %s', cost)
            else:
                last_save += 100
        if last_save > 1000:
            logger.info('No improvement after 1000 iterations. Stopping.')
            break