CoolFace
Apppublic

ignacy130/ner

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py20 linesDownload Raw Back to root
1import spacy  # version 3.0.6'2 3# initialize language model4nlp = spacy.load("en_core_web_md")5 6# add pipeline (declared through entry_points in setup.py)7nlp.add_pipe("entityLinker", last=True)8 9doc = nlp("I watched the Pirates of the Caribbean last silvester")10 11# returns all entities in the whole document12all_linked_entities = doc._.linkedEntities13# iterates over sentences and prints linked entities14for sent in doc.sents:15    sent._.linkedEntities.pretty_print()16 17# OUTPUT:18# https://www.wikidata.org/wiki/Q194318     Pirates of the Caribbean        Series of fantasy adventure films                                                                   19# https://www.wikidata.org/wiki/Q12525597   Silvester                       the day celebrated on 31 December (Roman Catholic Church) or 2 January (Eastern Orthodox Churches)20