spaCy/spacy/tests/regression/_test_issue1622.py

90 lines
3.2 KiB
Python
Raw Normal View History

2017-12-10 21:20:12 +00:00
# coding: utf-8
from __future__ import unicode_literals
2019-02-08 13:14:49 +00:00
2017-12-10 21:20:12 +00:00
import json
from tempfile import NamedTemporaryFile
2017-12-10 21:20:12 +00:00
2019-02-08 14:51:13 +00:00
from spacy.cli.train import train
2017-12-10 21:20:12 +00:00
def test_cli_trained_model_can_be_saved(tmpdir):
2019-02-08 13:14:49 +00:00
lang = "nl"
output_dir = str(tmpdir)
2019-02-08 13:14:49 +00:00
train_file = NamedTemporaryFile("wb", dir=output_dir, delete=False)
train_corpus = [
{
"id": "identifier_0",
"paragraphs": [
{
"raw": "Jan houdt van Marie.\n",
"sentences": [
{
"tokens": [
{
"id": 0,
"dep": "nsubj",
"head": 1,
"tag": "NOUN",
"orth": "Jan",
2019-02-08 13:14:49 +00:00
"ner": "B-PER",
},
{
"id": 1,
"dep": "ROOT",
"head": 0,
"tag": "VERB",
"orth": "houdt",
2019-02-08 13:14:49 +00:00
"ner": "O",
},
{
"id": 2,
"dep": "case",
"head": 1,
"tag": "ADP",
"orth": "van",
2019-02-08 13:14:49 +00:00
"ner": "O",
},
{
"id": 3,
"dep": "obj",
"head": -2,
"tag": "NOUN",
"orth": "Marie",
2019-02-08 13:14:49 +00:00
"ner": "B-PER",
},
{
"id": 4,
"dep": "punct",
"head": -3,
"tag": "PUNCT",
"orth": ".",
2019-02-08 13:14:49 +00:00
"ner": "O",
},
{
"id": 5,
"dep": "",
"head": -1,
"tag": "SPACE",
"orth": "\n",
2019-02-08 13:14:49 +00:00
"ner": "O",
},
],
2019-02-08 13:14:49 +00:00
"brackets": [],
}
2019-02-08 13:14:49 +00:00
],
}
2019-02-08 13:14:49 +00:00
],
}
]
2017-12-10 21:20:12 +00:00
2019-02-08 13:14:49 +00:00
train_file.write(json.dumps(train_corpus).encode("utf-8"))
train_file.close()
train_data = train_file.name
dev_data = train_data
2017-12-10 21:20:12 +00:00
# spacy train -n 1 -g -1 nl output_nl training_corpus.json training \
# corpus.json
train(lang, output_dir, train_data, dev_data, n_iter=1)
2017-12-10 21:20:12 +00:00
assert True