示例#1
0
    es_file = sys.argv[3] + "/es_" + sys.argv[2] + ".txt"
    es_epoch = sys.maxsize
    if os.path.isfile(es_file) == True:
        with open(es_file, 'r') as myfile:
            es_epoch = int(myfile.read())
            myfile.close()
    return es_epoch


if __name__ == "__main__":

    es_epoch = checkInputs()
    config = build_data(sys.argv[1])
    config.train_id_docs.extend(config.dev_id_docs)
    train_data = utils.HeadData(config.train_id_docs, np.arange(len(config.train_id_docs)))
    test_data = utils.HeadData(config.test_id_docs, np.arange(len(config.test_id_docs)))
    tf.reset_default_graph()
    tf.set_random_seed(1)
    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)
示例#2
0

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

gpuConfig = tf.ConfigProto(allow_soft_placement=True)
gpuConfig.gpu_options.allow_growth = True

if __name__ == "__main__":

    # checkInputs()

    config = build_data("./configs/CoNLL04/bio_config")

    train_data = utils.HeadData(config.train_id_docs,
                                np.arange(len(
                                    config.train_id_docs)))  ## build data
    dev_data = utils.HeadData(config.dev_id_docs,
                              np.arange(len(config.dev_id_docs)))
    test_data = utils.HeadData(config.test_id_docs,
                               np.arange(len(config.test_id_docs)))

    tf.reset_default_graph()
    tf.set_random_seed(1)

    utils.printParameters(config)

    with tf.Session(config=gpuConfig) as sess:
        embedding_matrix = tf.get_variable('embedding_matrix',
                                           shape=config.wordvectors.shape,
                                           dtype=tf.float32,