How to combine two NER HuggingFace pipelines with spacy-huggingface-pipelines #12815
-
I am trying to combine two HuggingFace models fine-tuned for NER, using
Then, loading a sentence with both cancer terms and proteins and combining the results:
Now, the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @CarlosGMPZ, I see what you're trying to do here, and the best approach will be to get your two components into one pipeline. To get this to work, you just have to give them each a unique name. If you don't do that, they take the factory name Then we need to make a few more adjustements. If you set both of them to
Then, when the pipeline has run, we'll want to put all spans together, filter them (to avoid overlapping entities) and store them to Altogether, you'd get something like this:
If you run this through |
Beta Was this translation helpful? Give feedback.
Hi @CarlosGMPZ,
I see what you're trying to do here, and the best approach will be to get your two components into one pipeline.
To get this to work, you just have to give them each a unique name. If you don't do that, they take the factory name
"hf_token_pipe"
by default and the second one will complain that the name already exists. You can set a different name withnlp.add_pipe(..., name=XXX)
.Then we need to make a few more adjustements. If you set both of them to
"annotate": "ents"
then yes, the second one will overwrite the first, which is not what we want. Instead, we'll let both components store their results indoc.spans
, each using a unique key, like so: