tf.flags.DEFINE_xxx()
最近在Bert代码中,看到了tf.flags.DEFINE的代码,不知道是什么含义,于是找到了一些资料。具体如下:
flags = tf.flags
FLAGS = flags.FLAGS
flags.DEFINE_xxx()
FLAGS.parse_flags()
函数意义
利用该函数,可以实现在命令行中设置需要设定的参数来运行程序。
这样的话,就可以不用在源代码中指定参数,相当于在命令行中传递需要设定的参数。
具体例子
程序run_classifer.py中的部分代码如下:
flags.DEFINE_string(
"data_dir", None,
"The input data dir. Should contain the .tsv files (or other data files) "
"for the task.")
flags.DEFINE_string(
"bert_config_file", None,
"The config json file corresponding to the pre-trained BERT model. "
"This specifies the model architecture.")
flags.DEFINE_string("task_name", None, "The name of the task to train.")
flags.DEFINE_string("vocab_file", None,
"The vocabulary file that the BERT model was trained on.")
flags.DEFINE_string(
"output_dir", None,
"The output directory where the