From a5debb356da68f2ef00a6c037d38f24d6ea41b92 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Wed, 30 Sep 2020 01:22:08 +0200 Subject: [PATCH] Tidy up and adjust logging [ci skip] --- spacy/cli/init_pipeline.py | 16 ++++++++++------ spacy/cli/train.py | 2 +- spacy/util.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/spacy/cli/init_pipeline.py b/spacy/cli/init_pipeline.py index d217ad366..f241133ca 100644 --- a/spacy/cli/init_pipeline.py +++ b/spacy/cli/init_pipeline.py @@ -27,7 +27,7 @@ def init_vectors_cli( you can use in the [initialize.vocab] block of your config to initialize a model with vectors. """ - util.logger.setLevel(logging.DEBUG if verbose else logging.ERROR) + util.logger.setLevel(logging.DEBUG if verbose else logging.INFO) msg.info(f"Creating blank nlp object for language '{lang}'") nlp = util.get_lang_class(lang)() convert_vectors(nlp, vectors_loc, truncate=truncate, prune=prune, name=name) @@ -55,14 +55,14 @@ def init_pipeline_cli( use_gpu: int = Opt(-1, "--gpu-id", "-g", help="GPU ID or -1 for CPU") # fmt: on ): - util.logger.setLevel(logging.DEBUG if verbose else logging.ERROR) + util.logger.setLevel(logging.DEBUG if verbose else logging.INFO) overrides = parse_config_overrides(ctx.args) import_code(code_path) setup_gpu(use_gpu) with show_validation_error(config_path): config = util.load_config(config_path, overrides=overrides) with show_validation_error(hint_fill=False): - nlp = init_nlp(config, use_gpu=use_gpu, silent=False) + nlp = init_nlp(config, use_gpu=use_gpu) nlp.to_disk(output_path) msg.good(f"Saved initialized pipeline to {output_path}") @@ -81,9 +81,12 @@ def init_labels_cli( use_gpu: int = Opt(-1, "--gpu-id", "-g", help="GPU ID or -1 for CPU") # fmt: on ): + """Generate a JSON file for labels in the data. This helps speed up the + training process, since spaCy won't have to preprocess the data to + extract the labels.""" + util.logger.setLevel(logging.DEBUG if verbose else logging.INFO) if not output_path.exists(): output_path.mkdir() - util.logger.setLevel(logging.DEBUG if verbose else logging.ERROR) overrides = parse_config_overrides(ctx.args) import_code(code_path) setup_gpu(use_gpu) @@ -93,7 +96,8 @@ def init_labels_cli( nlp = init_nlp(config, use_gpu=use_gpu) for name, component in nlp.pipeline: if getattr(component, "label_data", None) is not None: - srsly.write_json(output_path / f"{name}.json", component.label_data) - msg.good(f"Saving {name} labels to {output_path}/{name}.json") + output_file = output_path / f"{name}.json" + srsly.write_json(output_file, component.label_data) + msg.good(f"Saving {name} labels to {output_file}") else: msg.info(f"No labels found for {name}") diff --git a/spacy/cli/train.py b/spacy/cli/train.py index ed2dd7c83..aede0e8f4 100644 --- a/spacy/cli/train.py +++ b/spacy/cli/train.py @@ -40,7 +40,7 @@ def train_cli( DOCS: https://nightly.spacy.io/api/cli#train """ - util.logger.setLevel(logging.DEBUG if verbose else logging.ERROR) + util.logger.setLevel(logging.DEBUG if verbose else logging.INFO) verify_cli_args(config_path, output_path) overrides = parse_config_overrides(ctx.args) import_code(code_path) diff --git a/spacy/util.py b/spacy/util.py index 83a18b78a..761eb9f0a 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -67,7 +67,7 @@ CONFIG_SECTION_ORDER = ["paths", "variables", "system", "nlp", "components", "co # fmt: on -logging.basicConfig() +logging.basicConfig(format="%(message)s") logger = logging.getLogger("spacy")