further fixes to from_dict and to_dict

This commit is contained in:
svlandeg 2023-12-13 09:25:45 +01:00
parent b68053c6c8
commit c7c22a8dd5
2 changed files with 6 additions and 9 deletions

View File

@ -183,8 +183,8 @@ class Doc:
) -> Doc: ...
def to_bytes(self, *, exclude: Iterable[str] = ...) -> bytes: ...
def from_bytes(self, bytes_data: bytes, *, exclude: Iterable[str] = ...) -> Doc: ...
def to_dict(self, *, exclude: Iterable[str] = ...) -> bytes: ...
def from_dict(self, msg: bytes, *, exclude: Iterable[str] = ...) -> Doc: ...
def to_dict(self, *, exclude: Iterable[str] = ...) -> Dict[str, Any]: ...
def from_dict(self, msg: Dict[str, Any], *, exclude: Iterable[str] = ...) -> Doc: ...
def extend_tensor(self, tensor: Floats2d) -> None: ...
def retokenize(self) -> Retokenizer: ...
def to_json(self, underscore: Optional[List[str]] = ...) -> Dict[str, Any]: ...

View File

@ -1362,8 +1362,7 @@ cdef class Doc:
"""Export the document contents to a dictionary for serialization.
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (bytes): A losslessly serialized copy of the `Doc`, including
all annotations.
RETURNS (Dict[str, Any]): A dictionary representation of the `Doc`
"""
array_head = Doc._get_array_attrs()
strings = set()
@ -1409,13 +1408,11 @@ cdef class Doc:
return util.to_dict(serializers, exclude)
def from_dict(self, msg, *, exclude=tuple()):
"""Deserialize, i.e. import the document contents from a binary string.
"""Deserialize the document contents from a dictionary representation.
data (bytes): The string to load from.
exclude (list): String names of serialization fields to exclude.
msg (Dict[str, Any]): The dictionary to load from.
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (Doc): Itself.
DOCS: https://spacy.io/api/doc#from_dict
"""
if self.length != 0:
raise ValueError(Errors.E033.format(length=self.length))