Update serialization methods code block (#11004)

* Update serialization methods code block

* Update website/docs/usage/saving-loading.md

Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com>
This commit is contained in:
jademlc 2022-06-22 20:45:26 +02:00 committed by GitHub
parent 0fa004c4cd
commit bed23ff291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -203,11 +203,14 @@ the data to and from a JSON file.
```python
### {highlight="16-23,25-30"}
import json
from spacy import Language
from spacy.util import ensure_path
@Language.factory("my_component")
class CustomComponent:
def __init__(self):
def __init__(self, nlp: Language, name: str = "my_component"):
self.name = name
self.data = []
def __call__(self, doc):
@ -231,7 +234,7 @@ class CustomComponent:
# This will receive the directory path + /my_component
data_path = path / "data.json"
with data_path.open("r", encoding="utf8") as f:
self.data = json.loads(f)
self.data = json.load(f)
return self
```