Exemplo n.º 1
0
            if np.isnan(new_cost):
                print index, "nan"
            epoch_costs.append(new_cost)
            #validation
            if count == len(train_data):
                valLoss = []
                for i in range(len(dev_data)):
                    devInput = create_input(dev_data[i], parameters, True,
                                            None, False)
                    newDevCost = f_test(*devInput)
                    valLoss.append(newDevCost)
                #res_dev = evaluate(parameters, f_eval, dev_sentences,
                #              dev_data, id_to_tag, dico_tags,
                #            folder_out+fileNamePrefix+'.dev.txt',
                #            useAttend=False)
                eStop.on_epoch_end(epoch, np.mean(valLoss))
            if eStop.stop_training:
                break
        print BASH_YELLOW+"avg error:"+BASH_CLEAR,np.mean(epoch_costs),\
                    "avg dev loss:",np.mean(valLoss)
        print BASH_YELLOW + "One epch espliced:" + BASH_CLEAR, time.time(
        ) - startTime

    #start evaluate on test
    res_test = evaluate(parameters,
                        f_eval,
                        test_sentences,
                        test_data,
                        id_to_tag,
                        dico_tags,
                        folder_out + fileNamePrefix + '.test.txt',
Exemplo n.º 2
0
        if eStop.stop_training:
            break;
        
        print "Starting epoch %i..." % epoch
        for i, index in enumerate(np.random.permutation(len(train_data))):
            count += 1
            input = create_input(train_data[index], parameters, True, singletons)
            new_cost = f_train(*input)
            if np.isnan(new_cost):
                print index,"nan"
            epoch_costs.append(new_cost)
        #validation
        res_dev = evaluate(parameters, f_eval, dev_sentences,
                              dev_data, id_to_tag, dico_tags,
                            folder_out+fileNamePrefix+'.dev.txt')
        eStop.on_epoch_end(epoch,res_dev['f1']) ;
        print BASH_YELLOW+"avg error:"+BASH_CLEAR,np.mean(epoch_costs),\
                    " dev F1:",res_dev['f1'];
        print BASH_YELLOW+"One epch espliced:"+BASH_CLEAR,time.time()-startTime;

    #start evaluate on test
    res_test = evaluate(parameters, f_eval, test_sentences,
                      test_data, id_to_tag, dico_tags,
                    folder_out+fileNamePrefix+'.test.txt')
    if saveModel:
        print "Saving model to disk..."
        model.save()
    print BASH_RED+'TEST: epoch'+BASH_CLEAR, epoch, 'F1', res_test['f1'],'p:',res_test['p'],'r:',res_test['r'],  ' '*15
    print BASH_YELLOW+"model important point:"+BASH_CLEAR,opts.String;
            #}}}
else: