Help with trying to remove a custom pipeline factory #7316
-
Hello, I recently updated spacy to 3.0.3 (Windows 10, Python 3.7) and I am trying to build and debug a custom factory. As I find issues and errors in the factory, I would like to overwrite and re-add the factory to my Language. Here is the code I'm working with: @language.factory('my_factory')
def custom_factory(nlp: Language, name: str):
return None The issue is that, after adding the factory for the first time using the
I understand that this is because I am trying to create two functions of the same name, but I can not figure out a way to delete a custom factory once it has been added to my Language. Can someone help me figure out how to simply remove this custom factory so that I can debug it and re-add it to my list? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
+1, did you ever find a solution? |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late response to this. It sounds like you want to change the code for your component and re-add it in the same process. The components are not really designed to be used that way - even if you are debugging, the expectation is that you'll stop the process and start a new process as you redefine the component. This is why there is no Under the hood the registry is just using a dictionary with some extra state management on top, so if you want to dig into the internals there's probably a way to unset a key, but I really wouldn't recommend it. If you have a compelling use case for this we could think about adding it as a feature, but if you're just developing interactively I would encourage you to rethink your approach. |
Beta Was this translation helpful? Give feedback.
-
Hello, I think I have an use case for this. But perhaps anyone can point me to a better solution. So, long story short, we have several clients, and those clients have their own set of products. We need to recognize these products customer-wise. In order to do that, we:
So we would have many models consisting of an entity ruler + custom pipe that are client-specific; and then the same NER for all of them. Now, our setup is that we have a flask API of the type GET
I think this solution
Does the above workflow make sense? If it does, I'd really like to be able to import several models this way. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I just changed the name of the new component : instead of "language_detector" I called it "language_detector_v2" It worked for me
|
Beta Was this translation helpful? Give feedback.
Sorry for the late response to this.
It sounds like you want to change the code for your component and re-add it in the same process. The components are not really designed to be used that way - even if you are debugging, the expectation is that you'll stop the process and start a new process as you redefine the component. This is why there is no
registry.remove
function.Under the hood the registry is just using a dictionary with some extra state management on top, so if you want to dig into the internals there's probably a way to unset a key, but I really wouldn't recommend it.
If you have a compelling use case for this we could think about adding it as a feature, but if you're just dev…