tf.flags.DEFINE_integer("checkpoint_every", 100, "Save model after this many steps") tf.flags.DEFINE_integer("num_checkpoints", 1000, "Number of checkpoints to store") #tf.flags.DEFINE_string("checkpoint_dir", "", "Chechpoint directory") tf.flags.DEFINE_boolean("allow_soft_placement", True, "Allow device soft device placement") tf.flags.DEFINE_boolean("log_device_placement", False, "Log placement of ops on devices") FLAGS = tf.flags.FLAGS FLAGS._parse_flags() print("\nParameters:") for attr, value in sorted(FLAGS.__flags.items()): print("{}={}".format(attr.upper(), value)) print("") print("Loading data...") w = Word2Vec() train_data = MData(word2vec=w) train_data.open_file(FLAGS.positive_data_file, FLAGS.negative_data_file) print("=" * 50) print("training data size:", train_data.data_size) print("training max len:", train_data.max_len) print("=" * 50) with tf.Graph().as_default(): session_conf = tf.ConfigProto( allow_soft_placement=FLAGS.allow_soft_placement, log_device_placement=FLAGS.log_device_placement) session_conf.gpu_options.allow_growth=True sess = tf.Session(config=session_conf) with sess.as_default():
# --batch_size: batch size # --model_type: model type # --num_layers: number of convolution layers # --data_type: dataset with which we want to train our model ################################ # default parameters params = { "lr": 0.08, "ws": 4, "l2_reg": 0.0004, "epoch": 50, "batch_size": 200, "model_type": "BCNN", "num_layers": 2, "data_type": "BioASQ", "word2vec": Word2Vec() } ################################ print("=" * 50) print("Parameters:") for k in sorted(params.keys()): print(k, ":", params[k]) ################################ if len(sys.argv) > 1: for arg in sys.argv[1:]: k = arg.split("=")[0][2:] v = arg.split("=")[1] params[k] = v ################################ # Call train function to train our model train(
filter_size = int(FLAGS.filter_size) #----------------------------- define parameter end ---------------------------------- #----------------------------- define a logger ------------------------------- logger = logging.getLogger("test") logger.setLevel(logging.INFO) fh = logging.FileHandler("./test.log", mode="w") fh.setLevel(logging.INFO) logger.addHandler(fh) #----------------------------- define a logger end ---------------------------------- #------------------------------------load data ------------------------------- #load data word2Vec = Word2Vec() data_type = "WikiQA" if data_type == "WikiQA": test_data = WikiQA(word2vec=word2Vec) else: test_data = MSRP(word2vec=word2Vec) test_data.open_file(mode="test") #----------------------------------- load data end ---------------------- #----------------------------------- begin to train ----------------------------------- with tf.Graph().as_default(): with tf.device("/gpu:1"): gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=FLAGS.gpu_options) session_conf = tf.ConfigProto( allow_soft_placement=FLAGS.allow_soft_placement,