mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-15 11:00:34 +03:00
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:
parent
e2652f0fc0
commit
a2840ecd61
|
@ -203,11 +203,14 @@ the data to and from a JSON file.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
### {highlight="16-23,25-30"}
|
### {highlight="16-23,25-30"}
|
||||||
|
import json
|
||||||
|
from spacy import Language
|
||||||
from spacy.util import ensure_path
|
from spacy.util import ensure_path
|
||||||
|
|
||||||
@Language.factory("my_component")
|
@Language.factory("my_component")
|
||||||
class CustomComponent:
|
class CustomComponent:
|
||||||
def __init__(self):
|
def __init__(self, nlp: Language, name: str = "my_component"):
|
||||||
|
self.name = name
|
||||||
self.data = []
|
self.data = []
|
||||||
|
|
||||||
def __call__(self, doc):
|
def __call__(self, doc):
|
||||||
|
@ -231,7 +234,7 @@ class CustomComponent:
|
||||||
# This will receive the directory path + /my_component
|
# This will receive the directory path + /my_component
|
||||||
data_path = path / "data.json"
|
data_path = path / "data.json"
|
||||||
with data_path.open("r", encoding="utf8") as f:
|
with data_path.open("r", encoding="utf8") as f:
|
||||||
self.data = json.loads(f)
|
self.data = json.load(f)
|
||||||
return self
|
return self
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user