Esempio n. 1
0
def main(prog: str = None,
         model_overrides: Dict[str, str] = {},
         predictor_overrides: Dict[str, str] = {}) -> None:
    """
    The :mod:``allennlp.run`` command only knows about the registered classes
    in the ``allennlp`` codebase. In particular, once you start creating your own
    ``Model``s and so forth, it won't work for them. However, ``allennlp.run`` is
    simply a wrapper around this function. To use the command line interface with your
    own custom classes, just create your own script that imports all of the classes you want
    and then calls ``main()``.

    The default models for ``serve`` and the default predictors for ``predict`` are
    defined above. If you'd like to add more or use different ones, the
    ``model_overrides`` and ``predictor_overrides`` arguments will take precedence over the defaults.
    """
    # pylint: disable=dangerous-default-value
    ensure_pythonhashseed_set()

    parser = argparse.ArgumentParser(description="Run AllenNLP",
                                     usage='%(prog)s [command]',
                                     prog=prog)
    subparsers = parser.add_subparsers(title='Commands', metavar='')

    trained_models = {**DEFAULT_MODELS, **model_overrides}
    predictors = {**DEFAULT_PREDICTORS, **predictor_overrides}

    # Add sub-commands
    add_train_subparser(subparsers)
    add_evaluate_subparser(subparsers)
    add_predict_subparser(subparsers, predictors=predictors)
    add_serve_subparser(subparsers, trained_models=trained_models)

    args = parser.parse_args()

    # If a subparser is triggered, it adds its work as `args.func`.
    # So if no such attribute has been added, no subparser was triggered,
    # so give the user some help.
    if 'func' in dir(args):
        args.func(args)
    else:
        parser.print_help()
Esempio n. 2
0
def main(prog: str = None) -> None:
    ensure_pythonhashseed_set()

    parser = argparse.ArgumentParser(description="Run AllenNLP",
                                     usage='%(prog)s [command]',
                                     prog=prog)
    subparsers = parser.add_subparsers(title='Commands', metavar='')

    # Add sub-commands
    add_train_subparser(subparsers)
    add_evaluate_subparser(subparsers)
    add_predict_subparser(subparsers)
    add_serve_subparser(subparsers)

    args = parser.parse_args()

    # If a subparser is triggered, it adds its work as `args.func`.
    # So if no such attribute has been added, no subparser was triggered,
    # so give the user some help.
    if 'func' in dir(args):
        args.func(args)
    else:
        parser.print_help()