-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Labels
feat / docFeature: Doc, Span and Token objectsFeature: Doc, Span and Token objectsfeat / serializeFeature: Serialization, saving and loadingFeature: Serialization, saving and loading
Description
I'm having problems converting Docs to and from json. (I'm also getting errors with pickling in some cases, but the json problem is more reproducible.)
The docstring for .from_json() says that it takes a dict, but when I send a dict generated by to_json(), a doesn't apply to a 'dict' object error is raised.
Perhaps I'm using the methods wrongly, but I'm not sure how.
TIA
How to reproduce the behaviour
Python 3.11.4 (v3.11.4:d2340ef257, Jun 6 2023, 19:15:51) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
>>> nlp = spacy.load('en_core_web_sm')
>>> d=nlp("Dave saw Mary.")
>>> d
Dave saw Mary.
>>> j=d.to_json()
>>> spacy.tokens.doc.Doc.from_json(j)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'from_json' for 'spacy.tokens.doc.Doc' objects doesn't apply to a 'dict' object
>>>
Your Environment
Info about spaCy
- spaCy version: 3.7.4
- Platform: macOS-14.3.1-x86_64-i386-64bit
- Python version: 3.11.4
- Pipelines: en_core_web_sm (3.7.1)
Metadata
Metadata
Assignees
Labels
feat / docFeature: Doc, Span and Token objectsFeature: Doc, Span and Token objectsfeat / serializeFeature: Serialization, saving and loadingFeature: Serialization, saving and loading