SpaCy:如何获取 spacy 模型名称?
SpaCy: How to get the spacy model name?
它没有出现在 pip list
zeke$ pip list | grep spacy
spacy (1.7.3)
如何获取模型名称?
我试过了,但没用
echo "spaCy model:"
python3 -m sputnik --name spacy find
抛出此错误:
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'
从 spaCy 1.7.0 版开始,sputnik
包管理器已弃用。在您的版本中,您应该能够使用 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'
所有模型元数据也作为 Language
class 的 meta
属性公开,因此在您的脚本中,您可以执行以下操作:
nlp = spacy.load('en') # or any other model
print(nlp.meta['name'])
如果您通过 spaCy 的新 download
命令下载了模型,它们将作为 pip 包安装。这意味着当您在同一环境中 运行 pip list
或 pip freeze
时,它们应该会出现。
请注意,安装 spaCy 时不会自动下载模型,因此您必须单独下载它们(有关可用模型列表,请参阅 the docs):
python -m spacy download en # default English model (~50MB)
python -m spacy download en_core_web_md # larger English model (~1GB)
它没有出现在 pip list
zeke$ pip list | grep spacy
spacy (1.7.3)
如何获取模型名称?
我试过了,但没用
echo "spaCy model:"
python3 -m sputnik --name spacy find
抛出此错误:
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'
从 spaCy 1.7.0 版开始,sputnik
包管理器已弃用。在您的版本中,您应该能够使用 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'
所有模型元数据也作为 Language
class 的 meta
属性公开,因此在您的脚本中,您可以执行以下操作:
nlp = spacy.load('en') # or any other model
print(nlp.meta['name'])
如果您通过 spaCy 的新 download
命令下载了模型,它们将作为 pip 包安装。这意味着当您在同一环境中 运行 pip list
或 pip freeze
时,它们应该会出现。
请注意,安装 spaCy 时不会自动下载模型,因此您必须单独下载它们(有关可用模型列表,请参阅 the docs):
python -m spacy download en # default English model (~50MB)
python -m spacy download en_core_web_md # larger English model (~1GB)