no hyphens in model names?

When I try to package and install a newly-trained textcat model and if I give it a name with a hyphen in it, I can’t figure out how to import the resulting package.

$ python -m spacy package ./models/ /tmp/ --meta example_meta.json --force --create-meta`
    Model name (default: core_web_sm): jbmpp-3label
$ python sdist`
$ pip install en_jbmpp-3label-2.0.0.tar.gz # succeeds

$ python -c "import spacy; spacy.load('en_jbmpp_3label')"
ModuleNotFoundError: No module named 'en_jbmpp_3label'
$ python -c "import spacy; spacy.load('en_jbmpp-3label')"
ModuleNotFoundError: No module named 'en_jbmpp-3label'
$ python -c "import spacy; spacy.load('en-jbmpp-3label')"
ModuleNotFoundError: No module named 'en-jbmpp-3label'

When I go through the exact same workflow, but with a model name that doesn’t have a hyphen in it (e.g. jbmpp3label), everything works correctly.

I think this is a bug – albeit a small one and one that’s easy to work around – but I wanted to alert you to it. It threw me off for 20 minutes or so and wanted to (a) give the solution some google juice and (b) give you all a chance to fix it when you can.

It’s also possible I missing something.

Prodigy is super helpful, amazing software that’s sped me up significantly. Thank you!

Hi @jbmpp,

The packaging process bundles the model into a Python module, which needs to be named according to the normal Python naming rules. You’ll be able to something like import en_jbmpp_3label; nlp = jbmpp_3label.load(). Plainly you can’t do this if the name is something like en-jbmpp-3label – that would be a syntax error.

Hi @honnibal: Thanks! Makes sense. I wonder if there couldn’t be a warning in the spacy package workflow, rather than accepting a name with a hyphen. Or at least a note in the docs. It’s not immediately intuitive in spacy package that I’m naming a python module.

1 Like