in scripts/trainer.py [0:0]
def parse_args(args):
description = "Train the models"
main_parser = argparse.ArgumentParser(description=description)
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
"--limit",
type=int,
help="Only train on a subset of the data, used mainly for integrations tests",
)
parser.add_argument(
"--no-download",
action="store_false",
dest="download_db",
help="Do not download databases, uses whatever is on disk",
)
parser.add_argument(
"--download-eval",
action="store_true",
dest="download_eval",
help="Download databases and database support files required at runtime (e.g. if the model performs custom evaluations)",
)
parser.add_argument(
"--lemmatization",
help="Perform lemmatization (using spaCy)",
action="store_true",
)
subparsers = main_parser.add_subparsers(title="model", dest="model", required=True)
for model_name in MODELS:
subparser = subparsers.add_parser(
model_name, parents=[parser], help=f"Train {model_name} model"
)
try:
model_class_init = get_model_class(model_name).__init__
except ImportError:
continue
for parameter in inspect.signature(model_class_init).parameters.values():
if parameter.name == "self":
continue
# Skip parameters handled by the base class (TODO: add them to the common argparser and skip them automatically without hardcoding by inspecting the base class)
if parameter.name == "lemmatization":
continue
parameter_type = parameter.annotation
if parameter_type == inspect._empty:
parameter_type = type(parameter.default)
assert parameter_type is not None
if parameter_type is bool:
subparser.add_argument(
(
f"--{parameter.name}"
if parameter.default is False
else f"--no-{parameter.name}"
),
action=(
"store_true" if parameter.default is False else "store_false"
),
dest=parameter.name,
)
else:
subparser.add_argument(
f"--{parameter.name}",
default=parameter.default,
dest=parameter.name,
type=int,
)
return main_parser.parse_args(args)