Exemple #1
0
    utils.printParameters(config)

    # ---- Training ----
    config1 = tf.ConfigProto()
    config1.gpu_options.per_process_gpu_memory_fraction = 0.85
    with tf.Session(config=config1) as sess:
        # saver = tf.train.import_meta_graph('model.ckpt.meta')
        # saver.restore(sess, 'model.ckpt')
        embedding_matrix = tf.get_variable('embedding_matrix', shape=config.wordvectors.shape, dtype=tf.float32,
                                           trainable=False).assign(config.wordvectors)
        emb_mtx = sess.run(embedding_matrix)
        model = tf_utils.model(config, emb_mtx, sess)
        obj, m_op, predicted_op_ner, actual_op_ner, predicted_op_rel, actual_op_rel, score_op_rel = model.run()

        train_step = model.get_train_op(obj)
        operations = tf_utils.operations(train_step, obj, m_op, predicted_op_ner, actual_op_ner, predicted_op_rel,
                                         actual_op_rel, score_op_rel)

        sess.run(tf.global_variables_initializer())
        saver = tf.train.Saver()
        best_score = 0
        nepoch_no_imprv = 0  # for early stopping

        for iter in range(config.nepochs + 1):
            model.train(train_data, operations, iter)
            save_path = saver.save(sess, "model.ckpt")
            print("Model saved in path: %s" % save_path)

            # ---- Testing ----
        print("Starting Testing\n")

        saver = tf.train.import_meta_graph('model.ckpt.meta')
Exemple #2
0
        embedding_matrix = tf.get_variable('embedding_matrix',
                                           shape=config.wordvectors.shape,
                                           dtype=tf.float32,
                                           trainable=False).assign(
                                               config.wordvectors)
        emb_mtx = sess.run(embedding_matrix)

        model = tf_utils.model(config, emb_mtx, sess)

        obj, m_op, transition_params1, entity1Scores, predEntity1, transition_params2, entity2Scores, predEntity2 = model.run(
        )

        train_step = model.get_train_op(obj)

        operations = tf_utils.operations(train_step, obj, m_op,
                                         transition_params1, entity1Scores,
                                         predEntity1, transition_params2,
                                         entity2Scores, predEntity2)

        sess.run(tf.global_variables_initializer())

        best_score = 0
        min_loss = 0
        nepoch_no_imprv = 0  # for early stopping

        best_test_score = 0.

        for iter in range(config.nepochs + 1):

            loss = model.train(train_data, operations, iter)

            dev_score = model.evaluate(dev_data, operations, 'dev')