SpaCy: How to get the spacy model name?

Saravanabalagi Ramachandran picture Saravanabalagi Ramachandran · Mar 28, 2017 · Viewed 15.4k times · Source

It doesn't show up in pip list

zeke$ pip list | grep spacy
spacy (1.7.3)

How do I get the name of the model?


I tried this but it doesn't work

echo "spaCy model:"
python3 -m sputnik --name spacy find

Throws up this error:

zeke$ python3 -m sputnik --name spacy find
Traceback (most recent call last):
  File "/Users/zeke/anaconda/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Users/zeke/anaconda/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/__main__.py", line 28, in <module>
    main()
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/__main__.py", line 12, in main
    args.run(args)
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/cli.py", line 89, in run
    data_path=args.data_path)
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/__init__.py", line 114, in find
    obj = cls(app_name, app_version, expand_path(data_path))
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/pool.py", line 19, in __init__
    super(Pool, self).__init__(app_name, app_version, path, **kwargs)
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/package_list.py", line 33, in __init__
    self.load()
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/package_list.py", line 51, in load
    for package in self.packages():
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/package_list.py", line 47, in packages
    yield self.__class__.package_class(path=os.path.join(self.path, path))
  File "/Users/zeke/anaconda/lib/python3.5/site-packages/sputnik/package.py", line 15, in __init__
    super(Package, self).__init__(defaults=meta['package'])
KeyError: 'package'

Answer

Ines Montani picture Ines Montani · Mar 28, 2017

The sputnik package manager is deprecated as of spaCy version 1.7.0. In your version, you should be able to see all installed / linked models using spacy info:

python -m spacy info     # info about spaCy and installed models
python -m spacy info en  # info about model with the shortcut link 'en'

All model meta is also exposed as the meta attribute of the Language class, so from within your script, you can do:

nlp = spacy.load('en') # or any other model
print(nlp.meta['name'])

If you have downloaded models via spaCy's new download command, they'll be installed as pip packages. This means that they should show up when you run pip list or pip freeze from within the same environment.

Note that models are not downloaded automatically when you install spaCy, so you have to download them separately (see the docs for a list of available models):

python -m spacy download en              # default English model (~50MB)
python -m spacy download en_core_web_md  # larger English model (~1GB)