Пример #1
0
def train_model_from_file(parameter_filename: str, serialization_dir: str) -> Model:
    """
    A wrapper around :func:`train_model` which loads the params from a file.

    Parameters
    ----------
    param_path: str, required.
        A json parameter file specifying an AllenNLP experiment.
    serialization_dir: str, required
        The directory in which to save results and logs.
    """
    # We need the python hashseed to be set if we're training a model
    ensure_pythonhashseed_set()

    # Load the experiment config from a file and pass it to ``train_model``.
    params = Params.from_file(parameter_filename)
    return train_model(params, serialization_dir)
Пример #2
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()
Пример #3
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()
Пример #4
0
def test_pythonhashseed():
    ensure_pythonhashseed_set()