Rename spacy.analysis to spacy.pipe_analysis

This commit is contained in:
Ines Montani 2020-05-22 17:42:06 +02:00
parent 25d6ed3fb8
commit 4465cad6c5
3 changed files with 23 additions and 12 deletions

View File

@ -17,8 +17,8 @@ from .tokens.underscore import Underscore
from .vocab import Vocab
from .lemmatizer import Lemmatizer
from .lookups import Lookups
from .analysis import analyze_pipes, analyze_all_pipes, validate_attrs
from .analysis import count_pipeline_interdependencies
from .pipe_analysis import analyze_pipes, analyze_all_pipes, validate_attrs
from .pipe_analysis import count_pipeline_interdependencies
from .gold import Example
from .scorer import Scorer
from .util import link_vectors_to_models, create_default_optimizer, registry
@ -318,14 +318,18 @@ class Language(object):
# check whether we have a proper model config, or load a default one
if "model" in factory_cfg and not isinstance(factory_cfg["model"], dict):
warnings.warn(Warnings.W099.format(type=type(factory_cfg["model"]), pipe=name))
warnings.warn(
Warnings.W099.format(type=type(factory_cfg["model"]), pipe=name)
)
# refer to the model configuration in the cfg settings for this component
if "model" in factory_cfg:
self.config[name] = {"model": factory_cfg["model"]}
# create all objects in the config
factory_cfg = registry.make_from_config({"config": factory_cfg}, validate=True)["config"]
factory_cfg = registry.make_from_config({"config": factory_cfg}, validate=True)[
"config"
]
model = factory_cfg.get("model", None)
if model is not None:
del factory_cfg["model"]
@ -519,7 +523,16 @@ class Language(object):
def make_doc(self, text):
return self.tokenizer(text)
def update(self, examples, dummy=None, *, drop=0.0, sgd=None, losses=None, component_cfg=None):
def update(
self,
examples,
dummy=None,
*,
drop=0.0,
sgd=None,
losses=None,
component_cfg=None,
):
"""Update the models in the pipeline.
examples (iterable): A batch of `Example` or `Doc` objects.

View File

@ -187,10 +187,8 @@ def count_pipeline_interdependencies(pipeline):
counts = []
for i, assigns in enumerate(pipe_assigns):
count = 0
for requires in pipe_requires[i+1:]:
for requires in pipe_requires[i + 1 :]:
if assigns.intersection(requires):
count += 1
counts.append(count)
return counts

View File

@ -1,8 +1,8 @@
import spacy.language
from spacy.language import Language, component
from spacy.analysis import print_summary, validate_attrs
from spacy.analysis import get_assigns_for_attr, get_requires_for_attr
from spacy.analysis import count_pipeline_interdependencies
from spacy.pipe_analysis import print_summary, validate_attrs
from spacy.pipe_analysis import get_assigns_for_attr, get_requires_for_attr
from spacy.pipe_analysis import count_pipeline_interdependencies
from mock import Mock, ANY
import pytest
@ -169,7 +169,7 @@ def test_pipe_interdependencies():
name = "fancifier"
assigns = ("doc._.fancy",)
requires = tuple()
class FancyNeeder:
name = "needer"
assigns = tuple()