define command-line args parser
()
| 32 | |
| 33 | |
| 34 | def define_args_parser(): |
| 35 | """define command-line args parser""" |
| 36 | def _arg_bool(arg): |
| 37 | """trans arg to bool type |
| 38 | |
| 39 | Args: |
| 40 | arg (TYPE): NULL |
| 41 | |
| 42 | Returns: bool |
| 43 | """ |
| 44 | if arg is None: |
| 45 | return arg |
| 46 | |
| 47 | if type(arg) is not str: |
| 48 | return bool(arg) |
| 49 | |
| 50 | if arg.isdigit(): |
| 51 | return bool(int(arg)) |
| 52 | |
| 53 | if arg.lower() == 'true': |
| 54 | return True |
| 55 | else: |
| 56 | return False |
| 57 | |
| 58 | parser = argparse.ArgumentParser(description="text2sql command-line interface") |
| 59 | parser.add_argument('-c', '--config', default='conf/text2sql.jsonnet', |
| 60 | help='global config file path. it\'s priority is the lowest') |
| 61 | |
| 62 | general_args = parser.add_argument_group(title='general') |
| 63 | general_args.add_argument('--mode', type=str.lower, default='debug', required=False, |
| 64 | choices=['preproc', 'train', 'infer', 'test', 'debug']) |
| 65 | general_args.add_argument('--batch-size', type=int) |
| 66 | general_args.add_argument('--beam-size', default=1, type=int) |
| 67 | general_args.add_argument("--use-cuda", type=_arg_bool, default=True, help="is run in cuda mode") |
| 68 | general_args.add_argument("--is-eval-value", type=_arg_bool, default=True, help="is evaluating value") |
| 69 | general_args.add_argument("--is-cloud", type=_arg_bool, default=False, help="is run in paddle cloud") |
| 70 | general_args.add_argument("--is-debug", type=_arg_bool, default=False, help="is run in debug mode") |
| 71 | |
| 72 | model_args = parser.add_argument_group(title='model') |
| 73 | model_args.add_argument('--pretrain-model', help='ernie model path for dygraph') |
| 74 | model_args.add_argument('--init-model-params', help='trained model params') |
| 75 | model_args.add_argument('--init-model-optim', help='dumped model optimizer') |
| 76 | model_args.add_argument('--model-name', choices=['seq2tree_v2'], help='ernie model path for dygraph') |
| 77 | model_args.add_argument('--grammar-type', choices=['dusql_v2', 'nl2sql'], help='') |
| 78 | |
| 79 | data_args = parser.add_argument_group(title='data') |
| 80 | data_args.add_argument('--data-root', help='root data path. low priority.') |
| 81 | data_args.add_argument('--db', help='a tuple of pathes (schema, content) or path to dumped file') |
| 82 | data_args.add_argument('--db-schema', help='temp argument') |
| 83 | data_args.add_argument('--grammar', help='path to grammar definition file, or cached label vocabs directory') |
| 84 | data_args.add_argument('--train-set', help='original dataset path or dumped file path') |
| 85 | data_args.add_argument('--dev-set', help='original dataset path or dumped file path') |
| 86 | data_args.add_argument('--test-set', help='original dataset path or dumped file path') |
| 87 | data_args.add_argument('--eval-file', help='file to be evaluated(inferenced result)') |
| 88 | data_args.add_argument('--output', help='') |
| 89 | data_args.add_argument("--is-cached", type=_arg_bool, help="is dataset in cached format") |
| 90 | |
| 91 | train_args = parser.add_argument_group(title='train') |