@plac.annotations(<EOL>model=("<STR_LIT>", "<STR_LIT>", None, str),<EOL>data_path=("<STR_LIT>", "<STR_LIT>", None, str),<EOL>gold_preproc=("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", bool),<EOL>gpu_id=("<STR_LIT>", "<STR_LIT>", "<STR_LIT:g>", int),<EOL>displacy_path=("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", str),<EOL>displacy_limit=("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", int),<EOL>return_scores=("<STR_LIT>", "<STR_LIT>", "<STR_LIT:R>", bool),<EOL>)<EOL>def evaluate(<EOL>model,<EOL>data_path,<EOL>gpu_id=-<NUM_LIT:1>,<EOL>gold_preproc=False,<EOL>displacy_path=None,<EOL>displacy_limit=<NUM_LIT>,<EOL>return_scores=False,<EOL>):
msg = Printer()<EOL>util.fix_random_seed()<EOL>if gpu_id >= <NUM_LIT:0>:<EOL><INDENT>util.use_gpu(gpu_id)<EOL><DEDENT>util.set_env_log(False)<EOL>data_path = util.ensure_path(data_path)<EOL>displacy_path = util.ensure_path(displacy_path)<EOL>if not data_path.exists():<EOL><INDENT>msg.fail("<STR_LIT>", data_path, exits=<NUM_LIT:1>)<EOL><DEDENT>if displacy_path and not displacy_path.exists():<EOL><INDENT>msg.fail("<STR_LIT>", displacy_path, exits=<NUM_LIT:1>)<EOL><DEDENT>corpus = GoldCorpus(data_path, data_path)<EOL>nlp = util.load_model(model)<EOL>dev_docs = list(corpus.dev_docs(nlp, gold_preproc=gold_preproc))<EOL>begin = timer()<EOL>scorer = nlp.evaluate(dev_docs, verbose=False)<EOL>end = timer()<EOL>nwords = sum(len(doc_gold[<NUM_LIT:0>]) for doc_gold in dev_docs)<EOL>results = {<EOL>"<STR_LIT>": "<STR_LIT>" % (end - begin),<EOL>"<STR_LIT>": nwords,<EOL>"<STR_LIT>": "<STR_LIT>" % (nwords / (end - begin)),<EOL>"<STR_LIT>": "<STR_LIT>" % scorer.token_acc,<EOL>"<STR_LIT>": "<STR_LIT>" % scorer.tags_acc,<EOL>"<STR_LIT>": "<STR_LIT>" % scorer.uas,<EOL>"<STR_LIT>": "<STR_LIT>" % scorer.las,<EOL>"<STR_LIT>": "<STR_LIT>" % scorer.ents_p,<EOL>"<STR_LIT>": "<STR_LIT>" % scorer.ents_r,<EOL>"<STR_LIT>": "<STR_LIT>" % scorer.ents_f,<EOL>}<EOL>msg.table(results, title="<STR_LIT>")<EOL>if displacy_path:<EOL><INDENT>docs, golds = zip(*dev_docs)<EOL>render_deps = "<STR_LIT>" in nlp.meta.get("<STR_LIT>", [])<EOL>render_ents = "<STR_LIT>" in nlp.meta.get("<STR_LIT>", [])<EOL>render_parses(<EOL>docs,<EOL>displacy_path,<EOL>model_name=model,<EOL>limit=displacy_limit,<EOL>deps=render_deps,<EOL>ents=render_ents,<EOL>)<EOL>msg.good("<STR_LIT>".format(displacy_limit), displacy_path)<EOL><DEDENT>if return_scores:<EOL><INDENT>return scorer.scores<EOL><DEDENT>
Evaluate a model. To render a sample of parses in a HTML file, set an
output directory as the displacy_path argument.