mirror of
https://github.com/explosion/spaCy.git
synced 2025-07-13 01:32:32 +03:00
implement warning in __init_subclass__ instead
This commit is contained in:
parent
fb48de349c
commit
3f657ed3a1
|
@ -85,9 +85,9 @@ class Warnings:
|
||||||
"attribute or operator.")
|
"attribute or operator.")
|
||||||
|
|
||||||
# TODO: fix numbering after merging develop into master
|
# TODO: fix numbering after merging develop into master
|
||||||
W089 = ("The 'begin_training' method has been renamed to 'initialize', "
|
W088 = ("This component implements a 'begin_training' method, "
|
||||||
"for calls to 'nlp' as well as for the individual pipeline "
|
"which should probably be renamed to 'initialize'.")
|
||||||
"components.")
|
W089 = ("The nlp.begin_training method has been renamed to nlp.initialize.")
|
||||||
W090 = ("Could not locate any {format} files in path '{path}'.")
|
W090 = ("Could not locate any {format} files in path '{path}'.")
|
||||||
W091 = ("Could not clean/remove the temp directory at {dir}: {msg}.")
|
W091 = ("Could not clean/remove the temp directory at {dir}: {msg}.")
|
||||||
W092 = ("Ignoring annotations for sentence starts, as dependency heads are set.")
|
W092 = ("Ignoring annotations for sentence starts, as dependency heads are set.")
|
||||||
|
|
|
@ -1207,11 +1207,7 @@ class Language:
|
||||||
)
|
)
|
||||||
self.tokenizer.initialize(get_examples, nlp=self, **tok_settings)
|
self.tokenizer.initialize(get_examples, nlp=self, **tok_settings)
|
||||||
for name, proc in self.pipeline:
|
for name, proc in self.pipeline:
|
||||||
# backwards compatibility for older components
|
if hasattr(proc, "initialize"):
|
||||||
if hasattr(proc, "begin_training"):
|
|
||||||
warnings.warn(Warnings.W089, DeprecationWarning)
|
|
||||||
proc.begin_training(get_examples, pipeline=self.pipeline, sgd=self._optimizer)
|
|
||||||
elif hasattr(proc, "initialize"):
|
|
||||||
p_settings = I["components"].get(name, {})
|
p_settings = I["components"].get(name, {})
|
||||||
p_settings = validate_init_settings(
|
p_settings = validate_init_settings(
|
||||||
proc.initialize, p_settings, section="components", name=name
|
proc.initialize, p_settings, section="components", name=name
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# cython: infer_types=True, profile=True
|
# cython: infer_types=True, profile=True
|
||||||
|
import warnings
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
import srsly
|
import srsly
|
||||||
from thinc.api import set_dropout_rate, Model
|
from thinc.api import set_dropout_rate, Model
|
||||||
|
@ -6,7 +7,7 @@ from thinc.api import set_dropout_rate, Model
|
||||||
from ..tokens.doc cimport Doc
|
from ..tokens.doc cimport Doc
|
||||||
|
|
||||||
from ..training import validate_examples
|
from ..training import validate_examples
|
||||||
from ..errors import Errors
|
from ..errors import Errors, Warnings
|
||||||
from .. import util
|
from .. import util
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +34,13 @@ cdef class Pipe:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.cfg = dict(cfg)
|
self.cfg = dict(cfg)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __init_subclass__(cls, **kwargs):
|
||||||
|
"""Raise a warning if an inheriting class implements 'begin_training'
|
||||||
|
(from v2) instead of the new 'initialize' method (from v3)"""
|
||||||
|
if hasattr(cls, "begin_training"):
|
||||||
|
warnings.warn(Warnings.W088)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def labels(self) -> Optional[Tuple[str]]:
|
def labels(self) -> Optional[Tuple[str]]:
|
||||||
return []
|
return []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user