explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
30.15k stars 4.4k forks source link

UserWarning W123 printed on console after upgrading to 3.4.2 #11706

Closed asquare closed 2 years ago

asquare commented 2 years ago

After upgrading to 3.4.2 I see this warning on the console when a model is loaded. How to fix or silence this?

spacy/language.py:1895: UserWarning: [W123] Argument disable with value [] is used instead of ['senter'] as specified in the config. Be aware that this might affect other components in your pipeline.

How to reproduce the behaviour

import en_core_web_sm
lang_model = en_core_web_sm.load()

Your Environment

polm commented 2 years ago

Thanks for the heads-up, I confirmed this behavior. It's probably related to #11459.

This only happens for me when using the en_core_web_sm.load() style of loading - there's no warning with spacy.load().

We'll take a look at this, but it should be safe to ignore if the behavior it warns about is what you want. You can silence this the same was as any Python warning, like so:

import warnings
# message is a prefix of the actual warning string
warnings.filterwarnings("ignore", message="[W123]")
loctimize commented 2 years ago

When disabling a component with nlp = spacy.load('en_core_web_sm', disable=['ner']) the same error is triggered. Is this issue related?

I tried the fix suggest above with:

import warnings

warnings.filterwarnings("ignore", message="[W123]")

nlp = spacy.load('en_core_web_sm', disable=['ner'])

but it did not work. I am still getting this warning:

/Users/x/environments/python3.10.8/lib/python3.10/site-packages/spacy/language.py:1895: UserWarning: [W123] Argument disable with value ['ner'] is used instead of ['senter'] as specified in the config. Be aware that this might affect other components in your pipeline.
  warnings.warn(

UPDATE: warnings.filterwarnings("ignore", message="[W123]") needs to be

warnings.filterwarnings("ignore", message="^\[W123\]")

as message filter uses regex!

Any hint on how to correctly load the model without triggering the warning? Thx!

adrianeboyd commented 2 years ago

11713 fixed the warning for en_core_web_sm.load() but there are still some bugs related to the behavior of en_core_web_sm.load(disable=["ner"]) in v3.4.2.

adrianeboyd commented 2 years ago

A workaround to get the intended behavior for the sm/md/lg pipelines in v3.4.2 is to load the model like this:

nlp = spacy.load('en_core_web_sm', disable=['ner', 'senter'])

This will still produce a warning, though, and we are working on fixing both the behavior for disable=['ner'] and improving the warnings for cases that still need a warning.

If the warning is still causing problems for you and you don't need any of the modifications in v3.4.2, you can consider temporarily downgrading to v3.4.1.

adrianeboyd commented 2 years ago

To explain a bit more for anyone who comes across this issue, in v3.4.2 spacy.load("en_core_web_sm", disable=["ner"]) is doing two things:

  1. disables ner
  2. enables senter, which is otherwise disabled by default

In spacy v3.4.1 and earlier, the same command only did (1) and not (2). Enabling senter as a side effect is a bug, and we are working on addressing this for v3.4.3.

github-actions[bot] commented 1 year ago

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.