参数设置与获取
import argparse
parser = argparse.ArgumentParser()
# 没有加横杠的参数是必传参数, 不可缺省
parser.add_argument("train_path", help="the path of the train file", default="train.in")
parser.add_argument("save_path", help="the path of the saved model", default="model")
parser.add_argument("-v","--val_path", help="the path of the validation file", default="validation.in")
parser.add_argument("-e","--epoch", help="the number of epoch", default=100, type=int)
parser.add_argument("-c","--char_emb", help="the char embedding file", default=None)
parser.add_argument("-g","--gpu", help="the id of gpu, the default is 0", default=0, type=int)
args = parser.parse_args()
train_path = args.train_path
save_path = args.save_path
val_path = args.val_path
num_epochs = args.epoch
emb_path = args.char_emb
传入参数
python train.py train.in model -v validation.in -c char_emb -e 10 -g 2
python train.py train.in model -v validation.in -e 10