save_model("full_test.model", model)

            # p_sents_y, p_sents_t = model.predict(test_data_x_y[0][0], test_data_x_y[0][1],test_data_x_y[0][4], test_batch)
            # print ".........................predict....................."
            # get_data.print_sentence(p_sents_y, dim_y, i2w)
            # get_data.print_sentence(p_sents_t, dim_y, i2t)
            # print ".....................predict done...................."
            # ^ predict example ^
            t_bleu = []
            for tlen in xrange(len(test_data_x_y)):
                p_sents_y, p_sents_t = model.predict(test_data_x_y[tlen][0], test_data_x_y[tlen][1],test_data_x_y[tlen][4], test_batch)
                candidate_dic = get_data.get_candidate_dic_for_test_pos(sents_y, dim_y, i2w)
                batch_bleu, _ = print_bleu_normal_batch(candidate_dic, reference_dic, tlen * test_batch)
                t_bleu.append(batch_bleu)
            print "~~~~~~~~~~~~~Test Bleu is ", float(sum(t_bleu))/len(t_bleu), "~~~~~~~~~~~~~~~~"
            get_data.print_sentence_last_n(p_sents_y, dim_y, i2w, 1)
            get_data.print_sentence_last_n(p_sents_t, dim_tag, i2t, 1)

        
        print "read batch train last :"
        get_data.print_sentence_last_n(sents_y, dim_y, i2w, 1)
        get_data.print_sentence_last_n(sents_t, dim_tag, i2t, 1)


    E = float(error)/batch_split

    # if E < g_error:
    #     g_error = E
    #     print 'new smaller cost, save param...'
    #     save_model("0405-GRU-all-4hidden1000_best.model", model)
    # if error < 3.0:
        # l,r = model.predict(data_t1[0][0], data_t1[0][1],data_t1[0][3], data_t1[0][5], 1)
        # l2,r2 = model.predict(data_t2[0][0], data_t2[0][1],data_t2[0][3], data_t2[0][5], 1)
        # l3,r3 = model.predict(data_4[0][0], data_4[0][1],data_4[0][3], data_4[0][5], 1)
        # t_sents = model.predict(test_data_x_y[0][0], test_data_x_y[0][1],test_data_x_y[0][3], batch_size)
        #打印结果

        # print "Test : "
        # get_data.print_sentence(l, dim_y, i2w)
        # get_data.print_sentence(l2, dim_y, i2w)
        # get_data.print_sentence_last_n(t_sents[0], dim_y, i2w, 5)

    error /= len(data_x_y);
    
    print "Iter = " + str(i)+ " Error = " + str(error) + ", Time = " + str(in_b_time)
    if error < g_error:
        g_error = error
        print 'new smaller cost, save param...'
        save_model("GRU-200_best.model", model)
    if error < 2.0:
        print "train_last :"
        get_data.print_sentence_last_n(sents, dim_y, i2w, 20)


    if error <= e:
        break

# print "Finished. Time = " + str(time.time() - start)

# print "save model..."
# save_model("GRU-200_best-final.model", model)