I’m trying to build a custom spaCy model and as part of overriding the Thinc model predict function I need to detect the type of value returned by the Thinc function. If you place a breakpoint on ‘preds’ in the code below you can see the variable type changes between a numpy array and a 'spacy.ml.parser_model.ParserStepModel object'.
I was hoping someone knows how I can detect what the type of the variable ‘preds’ is, I've unsuccessfully tried isinstance.
import spacy
from thinc.model import Model, InT, OutT
import numpy as np
def predict(self, X:InT) -> OutT:
preds = self._func(self, X, is_train=False)[0]
return preds
Model.predict = predict
nlp = spacy.load('en_core_web_sm')
def show_ents(doc):
if doc.ents:
for ent in doc.ents:
print(ent.text + ' - ' + str(ent.start_char) + ' - ' + str(ent.end) + ' - ' +
ent.label_ + ' - ' + str(spacy.explain(ent.label_)))
else:
print('No named entities found.')
doc = nlp('Apple is looking at buying U.K. startup for $1 billion')
show_ents(doc)