2019-02-13 17:29:08 +03:00
|
|
|
# coding: utf8
|
2019-02-12 17:13:01 +03:00
|
|
|
from __future__ import unicode_literals
|
2019-02-13 17:29:08 +03:00
|
|
|
|
2019-02-12 17:13:01 +03:00
|
|
|
from spacy.lang.en import English
|
|
|
|
|
2019-02-13 17:29:08 +03:00
|
|
|
|
2019-02-12 17:13:01 +03:00
|
|
|
def test_issue3209():
|
2019-02-13 17:29:08 +03:00
|
|
|
"""Test issue that occurred in spaCy nightly where NER labels were being
|
2019-02-12 17:13:01 +03:00
|
|
|
mapped to classes incorrectly after loading the model, when the labels
|
|
|
|
were added using ner.add_label().
|
2019-02-13 17:29:08 +03:00
|
|
|
"""
|
2019-02-12 17:13:01 +03:00
|
|
|
nlp = English()
|
2019-02-13 17:29:08 +03:00
|
|
|
ner = nlp.create_pipe("ner")
|
2019-02-12 17:13:01 +03:00
|
|
|
nlp.add_pipe(ner)
|
2019-02-13 17:29:08 +03:00
|
|
|
|
|
|
|
ner.add_label("ANIMAL")
|
2019-02-12 17:13:01 +03:00
|
|
|
nlp.begin_training()
|
2019-02-13 17:29:08 +03:00
|
|
|
move_names = ["O", "B-ANIMAL", "I-ANIMAL", "L-ANIMAL", "U-ANIMAL"]
|
2019-02-12 17:13:01 +03:00
|
|
|
assert ner.move_names == move_names
|
|
|
|
nlp2 = English()
|
2019-02-13 17:29:08 +03:00
|
|
|
nlp2.add_pipe(nlp2.create_pipe("ner"))
|
2019-02-12 17:13:01 +03:00
|
|
|
nlp2.from_bytes(nlp.to_bytes())
|
2019-02-13 17:29:08 +03:00
|
|
|
assert nlp2.get_pipe("ner").move_names == move_names
|