Merge pull request #7471 from polm/fix/listener-warnings

This commit is contained in:
Ines Montani 2021-03-22 12:45:02 +01:00 committed by GitHub
commit 4bd3d01aaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 16 deletions

View File

@ -1686,8 +1686,14 @@ class Language:
) )
# Detect components with listeners that are not frozen consistently # Detect components with listeners that are not frozen consistently
for name, proc in nlp.pipeline: for name, proc in nlp.pipeline:
if getattr(proc, "listening_components", None): # e.g. tok2vec/transformer # Remove listeners not in the pipeline
for listener in proc.listening_components: listener_names = getattr(proc, "listening_components", [])
unused_listener_names = [ll for ll in listener_names if ll not in nlp.pipe_names]
for listener_name in unused_listener_names:
for listener in proc.listener_map.get(listener_name, []):
proc.remove_listener(listener, listener_name)
for listener in getattr(proc, "listening_components", []): # e.g. tok2vec/transformer
# If it's a component sourced from another pipeline, we check if # If it's a component sourced from another pipeline, we check if
# the tok2vec listeners should be replaced with standalone tok2vec # the tok2vec listeners should be replaced with standalone tok2vec
# models (e.g. so component can be frozen without its performance # models (e.g. so component can be frozen without its performance

View File

@ -72,8 +72,11 @@ def init_nlp(config: Config, *, use_gpu: int = -1) -> "Language":
logger.info(f"Initialized pipeline components: {nlp.pipe_names}") logger.info(f"Initialized pipeline components: {nlp.pipe_names}")
# Detect components with listeners that are not frozen consistently # Detect components with listeners that are not frozen consistently
for name, proc in nlp.pipeline: for name, proc in nlp.pipeline:
if getattr(proc, "listening_components", None): # e.g. tok2vec/transformer for listener in getattr(proc, "listening_components", []): # e.g. tok2vec/transformer
for listener in proc.listening_components: # Don't warn about components not in the pipeline
if listener not in nlp.pipe_names:
continue
if listener in frozen_components and name not in frozen_components: if listener in frozen_components and name not in frozen_components:
logger.warning(Warnings.W087.format(name=name, listener=listener)) logger.warning(Warnings.W087.format(name=name, listener=listener))
# We always check this regardless, in case user freezes tok2vec # We always check this regardless, in case user freezes tok2vec