def train_loop(main_program):
        exe.run(fluid.default_startup_program())
        embedding_param = fluid.global_scope().find_var(
            embedding_name).get_tensor()
        embedding_param.set(
            load_parameter(conll05.get_embedding(), word_dict_len, word_dim),
            place)

        start_time = time.time()
        batch_id = 0
        for pass_id in xrange(PASS_NUM):
            for data in train_data():
                cost = exe.run(main_program,
                               feed=feeder.feed(data),
                               fetch_list=[avg_cost])
                cost = cost[0]

                if batch_id % 10 == 0:
                    print("avg_cost:" + str(cost))
                    if batch_id != 0:
                        print("second per batch: " +
                              str((time.time() - start_time) / batch_id))
                    # Set the threshold low to speed up the CI test
                    if float(cost) < 60.0:
                        if save_dirname is not None:
                            # TODO(liuyiqun): Change the target to crf_decode
                            fluid.io.save_inference_model(
                                save_dirname, [
                                    'word_data', 'verb_data', 'ctx_n2_data',
                                    'ctx_n1_data', 'ctx_0_data', 'ctx_p1_data',
                                    'ctx_p2_data', 'mark_data'
                                ], [feature_out], exe)
                        return

                batch_id = batch_id + 1
Exemplo n.º 2
0
    def train_loop(main_program):
        exe.run(fluid.default_startup_program())
        embedding_param = fluid.global_scope().find_var(
            embedding_name).get_tensor()
        embedding_param.set(
            load_parameter(conll05.get_embedding(), word_dict_len, word_dim),
            place)

        start_time = time.time()
        batch_id = 0
        for pass_id in xrange(PASS_NUM):
            for data in train_data():
                cost = exe.run(main_program,
                               feed=feeder.feed(data),
                               fetch_list=[avg_cost])
                cost = cost[0]

                if batch_id % 10 == 0:
                    print("avg_cost:" + str(cost))
                    if batch_id != 0:
                        print("second per batch: " + str((time.time(
                        ) - start_time) / batch_id))
                    # Set the threshold low to speed up the CI test
                    if float(cost) < 60.0:
                        if save_dirname is not None:
                            # TODO(liuyiqun): Change the target to crf_decode
                            fluid.io.save_inference_model(save_dirname, [
                                'word_data', 'verb_data', 'ctx_n2_data',
                                'ctx_n1_data', 'ctx_0_data', 'ctx_p1_data',
                                'ctx_p2_data', 'mark_data'
                            ], [feature_out], exe)
                        return

                batch_id = batch_id + 1
Exemplo n.º 3
0
    def train_loop(main_program):
        exe.run(fluid.default_startup_program())

        embedding_param = fluid.global_scope().find_var(
            embedding_name).get_tensor()
        embedding_param.set(
            load_parameter(conll05.get_embedding(), word_dict_len, word_dim),
            place)

        start_time = time.time()
        batch_id = 0
        for pass_id in xrange(PASS_NUM):
            chunk_evaluator.reset(exe)
            for data in train_data():
                cost, precision, recall, f1_score = exe.run(
                    main_program,
                    feed=feeder.feed(data),
                    fetch_list=[avg_cost] + chunk_evaluator.metrics)
                pass_precision, pass_recall, pass_f1_score = chunk_evaluator.eval(
                    exe)

                if batch_id % 10 == 0:
                    print("avg_cost:" + str(cost) + " precision:" +
                          str(precision) + " recall:" + str(recall) +
                          " f1_score:" + str(f1_score) + " pass_precision:" +
                          str(pass_precision) + " pass_recall:" +
                          str(pass_recall) + " pass_f1_score:" +
                          str(pass_f1_score))
                    if batch_id != 0:
                        print("second per batch: " +
                              str((time.time() - start_time) / batch_id))
                    # Set the threshold low to speed up the CI test
                    if float(pass_precision) > 0.01:
                        if save_dirname is not None:
                            # TODO(liuyiqun): Change the target to crf_decode
                            fluid.io.save_inference_model(
                                save_dirname, [
                                    'word_data', 'verb_data', 'ctx_n2_data',
                                    'ctx_n1_data', 'ctx_0_data', 'ctx_p1_data',
                                    'ctx_p2_data', 'mark_data'
                                ], [feature_out], exe)
                        return

                batch_id = batch_id + 1
                          batch_size=BATCH_SIZE)

place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()

feeder = fluid.DataFeeder(feed_list=[
    word, ctx_n2, ctx_n1, ctx_0, ctx_p1, ctx_p2, predicate, mark, target
],
                          place=place)
exe = fluid.Executor(place)

main_program = fluid.default_main_program()

exe.run(fluid.default_startup_program())
embedding_param = fluid.global_scope().find_var(embedding_name).get_tensor()
embedding_param.set(
    load_parameter(conll05.get_embedding(), word_dict_len, word_dim), place)

start_time = time.time()
batch_id = 0
for pass_id in six.moves.xrange(PASS_NUM):
    for data in train_data():
        cost = exe.run(main_program,
                       feed=feeder.feed(data),
                       fetch_list=[avg_cost])
        cost = cost[0]

        if batch_id % 10 == 0:
            print("avg_cost: " + str(cost))
            if batch_id != 0:
                print("second per batch: " +
                      str((time.time() - start_time) / batch_id))