Where to register extension attributes that don't belong to a specific component? #7425
Replies: 1 comment 1 reply
-
I'd say this is the best solution for a use case like this. You could include this in the
An alternative option would be to insert an instance of a simple timing logging component in between all existing component (e.g. on
Just making it about timing is too specific and not really customisable enough – but I do see the general appeal of being able to hook into |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Setup
I have two extension attributes:
I have multiple custom components. I measure and store the time each of them takes in their respective
__call__()
methods like this:After running the pipeline, this gives me the timing information:
Question
In the docs, extension attributes are registered in the constructor of the component that sets them. My extension attributes are not related to a specific component, but rather to the pipeline/language as a whole. Every component writes to the extension attribute. Where do I set it?
Possible answers
Doc.set_extension()
in every component seems redundant and error prone. I would also have to make sure that the name is the same everywhere. If the getter was more complicated and wouldn't work as a lambda, I would even have to define the same function in every component.nlp.pipe_names
, it shows a component which does nothing in the pipeline.I basically need something like an
initialize
function on a pipeline/language which is not only called for training but also when the pipeline is loaded.(I originally asked three questions at once. I moved the other ones to #7445.)
Beta Was this translation helpful? Give feedback.
All reactions