我正在尝试从 Spacy 序列化 Doc 对象。看起来所有层次结构都没有被序列化。基本上我想序列化这个对象以通过 Rest 调用发送。
简单的测试用例如下:
import spacy
import jsonpickle
nlp = spacy.load('en_core_web_sm')
print(type(nlp))
text = "This is United States"
doc = nlp(text)
print('Output from noun_chunks before Serialization:')
for chunk in doc.noun_chunks:
print(chunk)
frozen = jsonpickle.encode(doc)
doc = jsonpickle.decode(frozen)
print(type(doc))
print('Output from noun_chunks after SerDe:')
for chunk in doc.noun_chunks:
print(chunk)
错误:
> Traceback (most recent call last): File "tests/temp.py", line 19, in
> <module>
> for chunk in doc.noun_chunks: File "doc.pyx", line 569, in noun_chunks ValueError: [E029] noun_chunks requires the dependency
> parse, which requires a statistical model to be installed and loaded.
> For more info, see the documentation: https://spacy.io/usage/models
>
> Process finished with exit code 1