Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将 spaCy 与 Python 一起用于命名实体识别,但脚本需要在每次运行时加载模型,并且需要大约 1.6GB 的内存来加载它。 但 1.6GB 并不是每次运行都可有可无。 如何将其加载到缓存或临时内存中以使脚本运行得更快?
首先你,如果你只做NER,你可以安装没有向量的解析器。这可以将参数解析器提供给:
python -m spacy.en.download parser
这将阻止下载700MB以上的Glove 向量,从而减少单次运行所需的内存。
然后,好吧,这取决于您对库的应用程序/使用情况。
如果您经常调用它,最好将其传递给在堆栈开头spacy.load('en')加载的模块/类变量。
spacy.load('en')
这会稍微减慢你的启动时间,但 spacy 将准备好(在内存中)被调用。
(如果开机时间有大问题,可以做懒加载)。