tutorials/nel_emerson/scripts/evaluate.py
def main(nlp_dir: Path, dev_set: Path):
    """ Step 4: Evaluate the new Entity Linking component by applying it to unseen text. """
    nlp = spacy.util.load_model_from_path(nlp_dir)
    examples = []
    with open(dev_set, "rb") as f:
        doc_bin = DocBin().from_disk(dev_set)
        docs = doc_bin.get_docs(nlp.vocab)
        for doc in docs:
            examples.append(Example(nlp(doc.text), doc))

    print()
    print("RESULTS ON THE DEV SET:")
    for example in examples:
        print(example.text)
        print(f"Gold annotation: {example.reference.ents[0].kb_id_}")
        print(f"Predicted annotation: {example.predicted.ents[0].kb_id_}")
        print()

    print()
    print("RUNNING THE PIPELINE ON UNSEEN TEXT:")
    text = "Tennis champion Emerson was expected to win Wimbledon."
    doc = nlp(text)
    print(text)
    for ent in doc.ents:
        print(ent.text, ent.label_, ent.kb_id_)
    print()
 Step 4: Evaluate the new Entity Linking component by applying it to unseen text. 
Step 4: Evaluate the new Entity Linking component by applying it to unseen text.
Step 4 : Evaluate the new Entity Linking component by applying it to unseen text .
def main(nlp_dir: Path, dev_set: Path):
    nlp = spacy.util.load_model_from_path(nlp_dir)
    examples = []
    with open(dev_set, "rb") as f:
        doc_bin = DocBin().from_disk(dev_set)
        docs = doc_bin.get_docs(nlp.vocab)
        for doc in docs:
            examples.append(Example(nlp(doc.text), doc))
    print()
    print("RESULTS ON THE DEV SET:")
    for example in examples:
        print(example.text)
        print(f"Gold annotation: {example.reference.ents[0].kb_id_}")
        print(f"Predicted annotation: {example.predicted.ents[0].kb_id_}")
        print()
    print()
    print("RUNNING THE PIPELINE ON UNSEEN TEXT:")
    text = "Tennis champion Emerson was expected to win Wimbledon."
    doc = nlp(text)
    print(text)
    for ent in doc.ents:
        print(ent.text, ent.label_, ent.kb_id_)
    print()
def main ( nlp_dir : Path , dev_set : Path ) : nlp = spacy . util . load_model_from_path ( nlp_dir ) examples = [ ] with open ( dev_set , "rb" ) as f : doc_bin = DocBin ( ) . from_disk ( dev_set ) docs = doc_bin . get_docs ( nlp . vocab ) for doc in docs : examples . append ( Example ( nlp ( doc . text ) , doc ) ) print ( ) print ( "RESULTS ON THE DEV SET:" ) for example in examples : print ( example . text ) print ( f"Gold annotation: {example.reference.ents[0].kb_id_}" ) print ( f"Predicted annotation: {example.predicted.ents[0].kb_id_}" ) print ( ) print ( ) print ( "RUNNING THE PIPELINE ON UNSEEN TEXT:" ) text = "Tennis champion Emerson was expected to win Wimbledon." doc = nlp ( text ) print ( text ) for ent in doc . ents : print ( ent . text , ent . label_ , ent . kb_id_ ) print ( )
Step 4: Evaluate the new Entity Linking component by applying it to unseen text.
Step 4 : Evaluate the new Entity Linking component by applying it to unseen text .
""" Step 4: Evaluate the new Entity Linking component by applying it to unseen text. """
nlp_dir
Path
dev_set
Path