From d1780db6a4b94669d9400af403bb6d5997aa5bd5 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Thu, 27 Aug 2020 18:56:55 +0200 Subject: [PATCH 1/2] Tidy up and use different error [ci skip] --- spacy/cli/_util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spacy/cli/_util.py b/spacy/cli/_util.py index e6002c92a..16e257ce2 100644 --- a/spacy/cli/_util.py +++ b/spacy/cli/_util.py @@ -6,6 +6,7 @@ from wasabi import msg import srsly import hashlib import typer +from click import NoSuchOption from typer.main import get_command from contextlib import contextmanager from thinc.config import Config, ConfigValidationError @@ -72,9 +73,10 @@ def parse_config_overrides(args: List[str]) -> Dict[str, Any]: opt = args.pop(0) err = f"Invalid CLI argument '{opt}'" if opt.startswith("--"): # new argument + orig_opt = opt opt = opt.replace("--", "") if "." not in opt: - msg.fail(f"{err}: can't override top-level section", exits=1) + raise NoSuchOption(orig_opt) if "=" in opt: # we have --opt=value opt, value = opt.split("=", 1) opt = opt.replace("-", "_") @@ -262,6 +264,7 @@ def upload_file(src: Path, dest: Union[str, "Pathy"]) -> None: url (str): The destination URL to upload to. """ import smart_open + dest = str(dest) with smart_open.open(dest, mode="wb") as output_file: with src.open(mode="rb") as input_file: @@ -277,6 +280,7 @@ def download_file(src: Union[str, "Pathy"], dest: Path, *, force: bool = False) If False, the download will be skipped. """ import smart_open + if dest.exists() and not force: return None src = str(src) From d3ffe4ca63bc2e581e30f115b74377b1f3f4c753 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 27 Aug 2020 18:56:58 +0200 Subject: [PATCH 2/2] Fix error when tagger was initialized with no labels --- spacy/pipeline/tagger.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spacy/pipeline/tagger.pyx b/spacy/pipeline/tagger.pyx index 2255a585a..af24bf336 100644 --- a/spacy/pipeline/tagger.pyx +++ b/spacy/pipeline/tagger.pyx @@ -286,7 +286,10 @@ class Tagger(Pipe): for tag in sorted(tags): self.add_label(tag) self.set_output(len(self.labels)) - self.model.initialize(X=doc_sample) + if self.labels: + self.model.initialize(X=doc_sample) + else: + self.model.initialize() if sgd is None: sgd = self.create_optimizer() return sgd