Add Tok2vec.remove_listener
@@ -82,6 +82,15 @@ class Tok2Vec(TrainablePipe):
self.listener_map.setdefault(component_name, [])
self.listener_map[component_name].append(listener)
+ def remove_listener(self, listener: "Tok2VecListener", component_name: str) -> None:
+ """Remove a listener for a downstream component. Usually internals."""
+ if component_name in self.listener_map:
+ if listener in self.listener_map[component_name]:
+ self.listener_map[component_name].remove(listener)
+ # If no listeners are left, remove entry
+ if not self.listener_map[component_name]:
+ del self.listener_map[component_name]
+
def find_listeners(self, component) -> None:
"""Walk over a model of a processing component, looking for layers that
are Tok2vecListener subclasses that have an upstream_name that matches
