2020-07-06 11:02:36 +00:00
|
|
|
from spacy.gold import Example
|
2019-10-02 10:50:48 +00:00
|
|
|
from spacy.lang.en import English
|
|
|
|
from spacy.util import minibatch, compounding
|
2019-11-16 19:20:53 +00:00
|
|
|
import pytest
|
2019-10-02 10:50:48 +00:00
|
|
|
|
|
|
|
|
2019-11-16 19:20:53 +00:00
|
|
|
@pytest.mark.filterwarnings("ignore::UserWarning")
|
2019-10-02 10:50:48 +00:00
|
|
|
def test_issue4348():
|
|
|
|
"""Test that training the tagger with empty data, doesn't throw errors"""
|
|
|
|
|
|
|
|
nlp = English()
|
2020-07-06 11:02:36 +00:00
|
|
|
example = Example.from_dict(nlp.make_doc(""), {"tags": []})
|
|
|
|
TRAIN_DATA = [example, example]
|
|
|
|
|
2019-10-02 10:50:48 +00:00
|
|
|
tagger = nlp.create_pipe("tagger")
|
|
|
|
nlp.add_pipe(tagger)
|
|
|
|
|
|
|
|
optimizer = nlp.begin_training()
|
|
|
|
for i in range(5):
|
|
|
|
losses = {}
|
|
|
|
batches = minibatch(TRAIN_DATA, size=compounding(4.0, 32.0, 1.001))
|
|
|
|
for batch in batches:
|
2019-11-11 16:35:27 +00:00
|
|
|
nlp.update(batch, sgd=optimizer, losses=losses)
|