Exemple #1
0
def train_mode():
    nnet_model = None
    if opts.nnet_struct:
        nnet_model = NNET_Model.parse_structure(opts.nnet_struct)
    elif opts.fname_in_model:
        nnet_model = NNET_Model.load(opts.fname_in_model)
    
    trainset = data_util.load_data(opts.fname_train)

    eos_pad = misc.get_pading(opts.eos_pad)

    train_data_resource = data_util.data_spliter(trainset, batchsize=opts.batchsize,
                            n_epoch=opts.n_epoch, EOS=eos_pad)

    optimizer, model = setup_training(nnet_model, opts)

    train_nnet(model, optimizer, train_data_resource, opts)
    if opts.fname_test:
        print('====================TESTING=========================')
        test_loss, pred, target = evaluation(model, opts.fname_test, show_progress=True)
        if 'cross_entropy' in opts.loss_function:
            misc.f_measure(pred, target)
        print(' test loss: %.3f' % test_loss)

    if opts.fname_out_model:
        nnet_model.save(opts.fname_out_model)
Exemple #2
0
def test_mode():
    loaded_model = NNET_Model.load(opts.fname_in_model)
    _, model = setup_training(loaded_model, opts)
    
    print('====================TESTING=========================')
    test_loss, pred, target = evaluation(model, opts.fname_test, show_progress=True)
    print(' test loss: %.3f' % test_loss)
    if 'cross_entropy' in opts.loss_function:
        misc.f_measure(pred, target)