gpt4 book ai didi

python - SpaCy:如何获取 spacy 模型名称?

转载 作者:太空狗 更新时间:2023-10-29 17:01:26 27 4
gpt4 key购买 nike

它没有出现在 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 类的 meta 属性公开,因此在您的脚本中,您可以:

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

如果您通过 spaCy 的新 download 命令下载了模型,它们将作为 pip 包安装。这意味着当您在同一环境中运行 pip listpip 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)

关于python - SpaCy:如何获取 spacy 模型名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43071775/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com