Repository navigation
Uisng imported function s a custom component #13758
Unanswered
widgetface
asked this question in
Help: Coding & Implementations
Replies: 1 comment
|
The component can live in a separate module. The important order is: import the module so its decorator runs, then call Here is a minimal layout:
from spacy.language import Language
from spacy.tokens import Span
from spacy.util import filter_spans
abbreviations = {"BP": "blood pressure"}
@Language.component("clinical_ner_tagger")
def clinical_ner_tagger(doc):
matches = [
Span(doc, token.i, token.i + 1, label="CLINICAL_ABBREVIATION")
for token in doc
if token.text in abbreviations
]
doc.ents = filter_spans([*doc.ents, *matches])
return doc
import spacy
import components.clinical_ner_tagger # registers the named component
nlp = spacy.blank("en")
nlp.add_pipe("clinical_ner_tagger", last=True)
doc = nlp("BP is normal.")
print([(entity.text, entity.label_) for entity in doc.ents])The expected entity is Your original code also only assigned Reference: spaCy custom pipeline components and registration. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 apologise straight off the bat if this is a dumb question , but I have only just started using SpaCy as a tool
I have a custom component at ./components/clinical_ner_tagger.py
I import this into my main.py file
custom component in a pipeline ? Al the examples have the custom component in the same file as the pipeline that is using the name attribute , but that doesn't work for imported files.
Again apologise for my basic question.
All reactions