【发布时间】:2020-02-15 21:33:40
【问题描述】:
我遵循了有关如何使用 NeuralCoref 进行train a a neural coreference 建模的指南。我现在有一个模型,但不知道如何在 Spacy 中使用 coref 模型。
手册中的以下内容并未描述如何加载自定义模型:
# Load your usual SpaCy model (one of SpaCy English models)
import spacy
nlp = spacy.load('custom-danish-spacy-model')
# Add neural coref to SpaCy's pipe
import neuralcoref
neuralcoref.add_to_pipe(nlp)
# You're done. You can now use NeuralCoref as you usually manipulate a SpaCy document annotations.
doc = nlp(u'A sentence in Danish. Another sentence in the same language.')
编辑:我尝试将经过训练的模型(通过运行 python -m neuralcoref.train.learn --train ./data/train/ --eval ./data/dev/ 生成)放入 NeuralCoref 缓存文件夹并运行上面的代码。出现以下错误:
return f(*args, **kwds)
/home/johan/Code/spacy-neuralcoref/venv/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: spacy.vocab.Vocab size changed, may indicate binary incompatibility. Expected 96 from C header, got 104 from PyObject
return f(*args, **kwds)
Traceback (most recent call last):
File "custom_model_test.py", line 5, in <module>
neuralcoref.add_to_pipe(nlp)
File "/home/johan/Code/spacy-neuralcoref/neuralcoref/neuralcoref/__init__.py", line 42, in add_to_pipe
coref = NeuralCoref(nlp.vocab, **kwargs)
File "neuralcoref.pyx", line 554, in neuralcoref.neuralcoref.NeuralCoref.__init__
File "neuralcoref.pyx", line 947, in neuralcoref.neuralcoref.NeuralCoref.from_disk
File "/home/johan/Code/spacy-neuralcoref/venv/lib/python3.6/site-packages/thinc/neural/_classes/model.py", line 355, in from_bytes
data = srsly.msgpack_loads(bytes_data)
File "/home/johan/Code/spacy-neuralcoref/venv/lib/python3.6/site-packages/srsly/_msgpack_api.py", line 29, in msgpack_loads
msg = msgpack.loads(data, raw=False, use_list=use_list)
File "/home/johan/Code/spacy-neuralcoref/venv/lib/python3.6/site-packages/srsly/msgpack/__init__.py", line 60, in unpackb
return _unpackb(packed, **kwargs)
File "_unpacker.pyx", line 199, in srsly.msgpack._unpacker.unpackb
srsly.msgpack.exceptions.ExtraData: unpack(b) received extra data.
【问题讨论】: