I have a Spacy NER model, where I am trying to extract each entity identified in a dataframe column as a separate column - so for example to create and populate the 'GPE' and 'PERSON columns:
Text | GPE | PERSON |
---|---|---|
random text London George | London | George |
However, i'm not sure how to do this and match the corresponding entities / label lists. I've trialled a few ways with no success such as:
def person(v):
if 'PERSON' in [ent.label_ for ent in ner_model(v).ents]:
return [ent.text for ent in ner_model(v).ents]
df['Person'] = df['Text'].apply(lambda v: person(v))
df.head()
This just returns a list of entities and I have been unable to get code containing '=='Person'' to work... I wondered if anyone else has solved this issue otherwise appreciate any help!