我在v2.0.12
中遇到问题,我已跟踪到thinc
。pip list
向我展示:
msgpack (0.5.6)
msgpack-numpy (0.4.3.1)
murmurhash (0.28.0)
regex (2017.4.5)
scikit-learn (0.19.2)
scipy (1.1.0)
spacy (2.0.12)
thinc (6.10.3)
我的代码在Mac上运行良好,但在生产中失败了。堆栈跟踪进入spacy
,然后进入thinc
——然后django真的崩溃了。当我使用早期版本的spacy时,这一切都起了作用——这是在我尝试升级到v2.0.12
之后才出现的。
我的requirements.txt文件有以下几行:
regex==2017.4.5
spacy==2.0.12
scikit-learn==0.19.2
scipy==1.1.0
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz
最后一行在部署期间下拉en_core_web_sm
。我这样做是为了在部署期间将这些模型加载到Heroku上。
然后我像这样加载解析器:
import en_core_web_sm
en_core_web_sm.load()
然后堆栈跟踪显示了thinc:
中的问题
File "spacy/language.py", line 352, in __call__
doc = proc(doc)
File "pipeline.pyx", line 426, in spacy.pipeline.Tagger.__call__
File "pipeline.pyx", line 438, in spacy.pipeline.Tagger.predict
File "thinc/neural/_classes/model.py", line 161, in __call__
return self.predict(x)
File "thinc/api.py", line 55, in predict
X = layer(X)
File "thinc/neural/_classes/model.py", line 161, in __call__
return self.predict(x)
File "thinc/api.py", line 293, in predict
X = layer(layer.ops.flatten(seqs_in, pad=pad))
File "thinc/neural/_classes/model.py", line 161, in __call__
eturn self.predict(x)
File "thinc/api.py", line 55, in predict
X = layer(X)
File "thinc/neural/_classes/model.py", line 161, in __call__
return self.predict(x)
File "thinc/neural/_classes/model.py", line 125, in predict
y, _ = self.begin_update(X)
File "thinc/api.py", line 374, in uniqued_fwd
Y_uniq, bp_Y_uniq = layer.begin_update(X_uniq, drop=drop)
File "thinc/api.py", line 61, in begin_update
X, inc_layer_grad = layer.begin_update(X, drop=drop)
File "thinc/neural/_classes/layernorm.py", line 51, in begin_update
X, backprop_child = self.child.begin_update(X, drop=0.)
File "thinc/neural/_classes/maxout.py", line 69, in begin_update
output__boc = self.ops.batch_dot(X__bi, W)
File "gunicorn/workers/base.py", line 192, in handle_abort
sys.exit(1)
再说一遍,这一切都适用于我的笔记本电脑。
我的装载方式有问题吗?或者我的thinc
版本已经过时了?如果是,我的requirements.txt
文件应该是什么样子?
我解决了这个问题,但会留下答案,以备其他人需要。
问题是,由于我如何以及何时构建和训练sklearn
模型,我的线程需要很长时间才能响应。结果,Heroku中止了线程——这就是堆栈跟踪显示abort
的原因。
修复方法是更改加载ML模型的方式和时间,这样这个特定的操作就不会超时。