aphp / edsnlp

Modular, fast NLP framework, compatible with Pytorch and spaCy, offering tailored support for French clinical notes.

Home Page:https://aphp.github.io/edsnlp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Edsnlp is interferring with spacy default behavior, and requires "trainable" dependencies

cvinot opened this issue · comments

Description

EDSnlp loader from edsnlp 10.0 (AliasLoader in edsnlp init.py) is interferring with spacy default loader it seems, which creates additionnal dependencies from the edsnlp trainable components which are not listed, if intended.

How to reproduce the bug

In a fresh environment

poetry add edsnlp
download a spacy model, for example fr_core_news_sm-3.5

then:

from spacy import load
model = "fr_core_news_sm-3.5"
nlp = load(model)

Here it raises errors depending on the environment, "foldedtensor" or in our case "torch" module not found. which is not a dependency in any package, as edsnlp[ml] was not desired.

Other

I found the bug with this snippet:

import spacy
model = "fr_core_news_sm-3.5"
nlp = spacy.load(model)

Which raises [E002] Can't find factory for 'tok2vec' for language French (fr). and shows no relation to edsnlp whatsoever interestingly enough.

Hi, thank you for letting us know about this ! This is indeed problematic. By default, spacy imports all available components (i.e., that have a spacy_factories entrypoint namespace), even though they are not required by the user. You did not install edsnlp[ml] indeed, so importing some components like eds.transformer will fail, hence the bug you reported.

You can try with to re-install edsnlp with the fix from #235, let me know if this works for you !

pip install git+https://github.com/aphp/edsnlp@fix-non-ml-install

Interesting, I never dived into these depths of spacy.

It does fix the issue for me at first glance. Great reactivity, thanks.

I still have the same problem if I import part of edsnlp though.

import spacy
import edsnlp
model = "fr_core_news_sm-3.5"
nlp = spacy.load(model)

or even

import spacy
from edsnlp.language import EDSTokenizer
model = "fr_core_news_sm-3.5"
nlp = spacy.load(model)

raise the same error.

Ok thank you for testing, the new fix in #235 (same pip install git+https://github.com/aphp/edsnlp@fix-non-ml-install) should do the trick now 🤞