mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-29 09:23:12 +03:00
Proactively remove unused listeners
With this the changes in initialize.py might be unecessary. Requires testing.
This commit is contained in:
parent
ef77c88638
commit
40bc01e668
|
@ -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
|
||||||
|
|
|
@ -72,10 +72,9 @@ 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
|
# Don't warn about components not in the pipeline
|
||||||
if listener not in nlp.pipeline:
|
if listener not in nlp.pipe_names:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if listener in frozen_components and name not in frozen_components:
|
if listener in frozen_components and name not in frozen_components:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user