snipsco / snips-nlu

Snips Python library to extract meaning from text
https://snips-nlu.readthedocs.io
Apache License 2.0
3.89k stars 513 forks source link

[0.20.0] load_resources depreciation #846

Closed YuukanOO closed 5 years ago

YuukanOO commented 5 years ago

As mentionned in #750, I use load_resources (especially on Windows when linking fail). After updating to 0.20.0, I get this warning:

DeprecatedWarning: load_resources is deprecated as of 0.19.7 and will be removed in 0.21.0. Loading resources in the client code is no longer required

when using this code:

from snips_nlu.default_configs import CONFIG_EN
from snips_nlu import SnipsNLUEngine, load_resources

SnipsNLUEngine(CONFIG_EN, resources=load_resources('snips_nlu_en'))

If I remove the load_resources call as mentionned per the warning, it doesn't work and I'm back with this:

snips_nlu.resources.MissingResource: Language resource 'en' not found. This may be solved by running 'python -m snips_nlu download en'

So my question is: what is the recommended way, as of snips-nlu 0.20.0, to load resources that will still work when the 0.21.0 goes out?

adrienball commented 5 years ago

@YuukanOO , The load_resources function will not be removed, however it will no longer be imported in the __init__.py of the snips_nlu package. Instead, you can import it as follow:

from snips_nlu.resources import load_resources 

This is already available, so you can already switch in order to avoid troubles when you update to 0.21.0.

The reason of this change, and of this warning, is mostly to inform users that, in general, loading resources is no longer required. In your case, as the resources linking fails, it still makes sense to load resources manually.

I'm curious about the linking error, can you provide details about it? Any idea what could cause it? Are you running withing a virtual environment? Thanks

YuukanOO commented 5 years ago

Good to know! I'll update then, thanks for the quick answer ;)

After your answer I doubled check and if I'm running the command python -m snips_nlu download fr as an administrator, linking succeeded. You were right here too (on Windows i'm not using venv, shame on me).

But I think I will still use the manual load_resources since I use it to automatically download resources as needed (https://github.com/atlassistant/pytlas/blob/develop/pytlas/understanding/snips.py#L97).

Thanks!