()
| 44 | |
| 45 | |
| 46 | def main(): |
| 47 | parser = argparse.ArgumentParser() |
| 48 | parser.add_argument('mode', help="preprocess/train/eval") |
| 49 | parser.add_argument('exp_config_file', help="jsonnet file for experiments") |
| 50 | args = parser.parse_args() |
| 51 | |
| 52 | exp_config = json.loads(_jsonnet.evaluate_file(args.exp_config_file)) |
| 53 | model_config_file = exp_config["model_config"] |
| 54 | if "model_config_args" in exp_config: |
| 55 | model_config_args = json.dumps(exp_config["model_config_args"]) |
| 56 | else: |
| 57 | model_config_args = None |
| 58 | |
| 59 | if args.mode == "preprocess": |
| 60 | preprocess_config = PreprocessConfig(model_config_file, \ |
| 61 | model_config_args) |
| 62 | preprocess.main(preprocess_config) |
| 63 | elif args.mode == "train": |
| 64 | train_config = TrainConfig(model_config_file, |
| 65 | model_config_args, exp_config["logdir"]) |
| 66 | train.main(train_config) |
| 67 | elif args.mode == "eval": |
| 68 | for step in exp_config["eval_steps"]: |
| 69 | infer_output_path = "{}/{}-step{}.infer".format( |
| 70 | exp_config["eval_output"], |
| 71 | exp_config["eval_name"], |
| 72 | step) |
| 73 | infer_config = InferConfig( |
| 74 | model_config_file, |
| 75 | model_config_args, |
| 76 | exp_config["logdir"], |
| 77 | exp_config["eval_section"], |
| 78 | exp_config["eval_beam_size"], |
| 79 | infer_output_path, |
| 80 | step, |
| 81 | use_heuristic=exp_config["eval_use_heuristic"] |
| 82 | ) |
| 83 | infer.main(infer_config) |
| 84 | |
| 85 | eval_output_path = "{}/{}-step{}.eval".format( |
| 86 | exp_config["eval_output"], |
| 87 | exp_config["eval_name"], |
| 88 | step) |
| 89 | eval_config = EvalConfig( |
| 90 | model_config_file, |
| 91 | model_config_args, |
| 92 | exp_config["logdir"], |
| 93 | exp_config["eval_section"], |
| 94 | infer_output_path, |
| 95 | eval_output_path |
| 96 | ) |
| 97 | eval.main(eval_config) |
| 98 | |
| 99 | res_json = json.load(open(eval_output_path)) |
| 100 | print(step, res_json['total_scores']['all']['exact']) |
| 101 | |
| 102 | |
| 103 | if __name__ == "__main__": |
no test coverage detected