mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-01 00:17:44 +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
							
								
									0fa004c4cd
								
							
						
					
					
						commit
						bed23ff291
					
				|  | @ -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