Wrapping a textcat in a custom component #10182
Replies: 3 comments 1 reply
-
Is the issue in having the signatures not aligned. The factory passes |
Beta Was this translation helpful? Give feedback.
-
WorkaroundMy current workaround is to have only this part in my config
Then I load the component like this import spacy
from pathlib import Path
from spacy.pipeline.textcat_multilabel import MultiLabel_TextCategorizer
@Language.factory("my_component", default_config={"textcat": None})
def create_my_component(nlp, name, textcat: MultiLabel_TextCategorizer):
textcat = spacy.load(
Path(__file__).parent / "model", vocab=nlp.vocab
).get_pipe("textcat_multilabel")
return MyComponent(textcat)
class MyComponent:
def __init__(self, textcat):
this.textcat = textcat Note this requires an entire pipeline in |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delayed reply to this. Have you looked at the spancat? It's still not as well documented as our other components, but it's a pretty natural fit for labelling each sentence in a document. About your component / issue here more generally, it might be easier to subclass the textcat and modify some of the methods on it to get the behavior your want rather than putting it inside another component. Things like serialization etc. should also just work. Another approach is of course to split your docs up, using one doc for each sentence, and then using a normal pipeline with textcat and reassembling the docs later. |
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.
-
I have a custom component that runs text categorization on each sentence in a
Doc
. This was build in a kinda hacky way inv2
. Now I want to update it to work inv3
with the new config system.Initially I was thinking something like this
and with a config like this
I have my component registered fine but I'm getting the following error when I'm using
spacy.load
I didn't expect it to work since I still need to point to where my
textcat
model can actually be found but yeah...Beta Was this translation helpful? Give feedback.
All reactions