mirror of https://github.com/explosion/spaCy.git
Fix tests
This commit is contained in:
parent
55d0621532
commit
bb98d45a63
|
@ -55,19 +55,13 @@ def additional_entity_types():
|
|||
|
||||
@contextlib.contextmanager
|
||||
def temp_save_model(model):
|
||||
model_dir = Path(tempfile.mkdtemp())
|
||||
# store the fine tuned model
|
||||
with (model_dir / "config.json").open('w') as file_:
|
||||
data = json.dumps(model.cfg)
|
||||
if not isinstance(data, unicode):
|
||||
data = data.decode('utf8')
|
||||
file_.write(data)
|
||||
model.model.dump((model_dir / 'model').as_posix())
|
||||
model_dir = tempfile.mkdtemp()
|
||||
model.to_disk(model_dir)
|
||||
yield model_dir
|
||||
shutil.rmtree(model_dir.as_posix())
|
||||
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
@pytest.mark.models('en')
|
||||
def test_issue910(EN, train_data, additional_entity_types):
|
||||
'''Test that adding entities and resuming training works passably OK.
|
||||
|
@ -84,18 +78,20 @@ def test_issue910(EN, train_data, additional_entity_types):
|
|||
for entity_type in additional_entity_types:
|
||||
nlp.entity.add_label(entity_type)
|
||||
|
||||
nlp.entity.model.learn_rate = 0.001
|
||||
sgd = Adam(nlp.entity.model[0].ops, 0.001)
|
||||
for itn in range(10):
|
||||
random.shuffle(train_data)
|
||||
for raw_text, entity_offsets in train_data:
|
||||
doc = nlp.make_doc(raw_text)
|
||||
nlp.tagger(doc)
|
||||
nlp.tensorizer(doc)
|
||||
gold = GoldParse(doc, entities=entity_offsets)
|
||||
loss = nlp.entity.update(doc, gold)
|
||||
loss = nlp.entity.update(doc, gold, sgd=sgd, drop=0.5)
|
||||
|
||||
with temp_save_model(nlp.entity) as model_dir:
|
||||
# Load the fine tuned model
|
||||
loaded_ner = EntityRecognizer.load(model_dir, nlp.vocab)
|
||||
loaded_ner = EntityRecognizer(nlp.vocab)
|
||||
loaded_ner.from_disk(model_dir)
|
||||
|
||||
for raw_text, entity_offsets in train_data:
|
||||
doc = nlp.make_doc(raw_text)
|
||||
|
|
|
@ -4,7 +4,7 @@ import pytest
|
|||
|
||||
|
||||
@pytest.mark.models('en')
|
||||
def test_issue955(EN, doc):
|
||||
def test_issue955(EN):
|
||||
'''Test that we don't have any nested noun chunks'''
|
||||
doc = EN('Does flight number three fifty-four require a connecting flight'
|
||||
' to get to Boston?')
|
||||
|
|
Loading…
Reference in New Issue