From 93cf4af7018f3e1a6dd3dda0df9595eb4afe3f18 Mon Sep 17 00:00:00 2001 From: Christos Savvopoulos Date: Mon, 12 Dec 2016 20:13:33 +0000 Subject: [PATCH 1/2] actually commit load_ner.py --- examples/training/load_ner.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/training/load_ner.py diff --git a/examples/training/load_ner.py b/examples/training/load_ner.py new file mode 100644 index 000000000..ae6fe1527 --- /dev/null +++ b/examples/training/load_ner.py @@ -0,0 +1,22 @@ +# Load NER +from __future__ import unicode_literals +import spacy +import pathlib +from spacy.pipeline import EntityRecognizer +from spacy.vocab import Vocab + +def load_model(model_dir): + model_dir = pathlib.Path(model_dir) + nlp = spacy.load('en', parser=False, entity=False, add_vectors=False) + with (model_dir / 'vocab' / 'strings.json').open('r', encoding='utf8') as file_: + nlp.vocab.strings.load(file_) + nlp.vocab.load_lexemes(model_dir / 'vocab' / 'lexemes.bin') + ner = EntityRecognizer.load(pathlib.Path("ner"), nlp.vocab, require=True) + return (nlp, ner) + +(nlp, ner) = load_model('ner') +doc = nlp.make_doc('Who is Shaka Khan?') +nlp.tagger(doc) +ner(doc) +for word in doc: + print(word.text, word.orth, word.lower, word.tag_, word.ent_type_, word.ent_iob) From c19b83f6ae42634d6b2a1403bebf328edcd61de6 Mon Sep 17 00:00:00 2001 From: Christos Savvopoulos Date: Mon, 12 Dec 2016 20:23:24 +0000 Subject: [PATCH 2/2] use model_dir inside of load_model --- examples/training/load_ner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/training/load_ner.py b/examples/training/load_ner.py index ae6fe1527..bf81cee50 100644 --- a/examples/training/load_ner.py +++ b/examples/training/load_ner.py @@ -11,7 +11,7 @@ def load_model(model_dir): with (model_dir / 'vocab' / 'strings.json').open('r', encoding='utf8') as file_: nlp.vocab.strings.load(file_) nlp.vocab.load_lexemes(model_dir / 'vocab' / 'lexemes.bin') - ner = EntityRecognizer.load(pathlib.Path("ner"), nlp.vocab, require=True) + ner = EntityRecognizer.load(model_dir, nlp.vocab, require=True) return (nlp, ner) (nlp, ner) = load_model('ner')