spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Failure to load a model should be an error or a warning, not a message

Open bgbg opened this issue 8 years ago • 2 comments

Sometimes, spacy fails to load a model (for example, see #924 ). In these cases, the user should be able to detect the problem in a non-interactive way. For example, using a try-catch pattern, in case of exceptions, or by catching a warning [ref]. Right now, the load function prints a warning message using util.print_msg which escapes any assertion mechanism.

There are two ways to address this problem without breaking back compatibility:

  • add an optional argument to load, so that we can type scipy.load('en', raise_on_failure=True)
  • change the current call to util.print_msg to warnings.warn

I think that the first one is safer

bgbg avatar Mar 29 '18 09:03 bgbg

Hi! From your descriptions, it sounds like you're using an older version of spaCy, right? There were various problems and inconsistencies around this in v1.x, which we've now fixed and addressed in spaCy v2.x – the most important one being spacy.load doing too many things at once (loading models, loading language data). This resulted in awkward states where the failure to load a model wasn't exactly a failure, because it'd fall back to only loading the tokenizer.

In v2.0+, spacy.load has been improved and is now only intended for loading models. If any of that fails, spaCy will raise the respective errors. Since this is a significant change, we've only introduced this with the major version change. The CLI commands now also exit with the correct codes, so you can run them as part of an automated process – including spacy validate, which will exit with 1 if you have incompatible models installed.

(Still good timing of your issue btw – I'm just about to publish a PR that includes various improvements to spaCy's error handling system, as well as options to show custom library-specific warnings. Happy to update the thread once the PR is published and would appreciate your feedback on the changes and ideas 😊 Edit: See #2163 and #2164!)

ines avatar Mar 29 '18 09:03 ines

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar May 07 '18 17:05 lock[bot]