I'd like to create a custom pipeline component in spaCy which uses a pre-trained Thinc model. I'd like to modify the output prediction from Thinc and then pass the modified value back into the pipeline i.e. effectively modifying the ner pipeline component.
I was thinking of doing this via a custom pipeline component, something like:
from spacy.language import Language
@Language.component("my_ner")
def my_ner(doc):
class_probabilities = thinc_do_something(data, model, num_samples)
class_value = np.argmax(class_probabilities, axis=1)
return doc
nlp = spacy.load("en_core_web_sm", exclude=["ner"])
nlp.add_pipe("my_ner", after="parser") # Insert after the parser
print(nlp.pipe_names) # ['tagger', 'parser', 'my_ner']
doc = nlp("This is a sentence.")
My aim is for the pipe to run as per the original ner component, but with my custom ner component modifying the class probabilities. Unfortunately I don't understand from the spaCy documentation:
- How to access the pre trained model from inside the pipeline?
- How to access the data used for the model prediction within the pipeline?
- Where I need to write the model predicted value back to as part of my modified ner pipline?
- Is there a better way of doing this?
