mirror of
https://github.com/explosion/spaCy.git
synced 2024-09-21 19:39:13 +03:00
75f3234404
## Description Related issues: #2379 (should be fixed by separating model tests) * **total execution time down from > 300 seconds to under 60 seconds** 🎉 * removed all model-specific tests that could only really be run manually anyway – those will now live in a separate test suite in the [`spacy-models`](https://github.com/explosion/spacy-models) repository and are already integrated into our new model training infrastructure * changed all relative imports to absolute imports to prepare for moving the test suite from `/spacy/tests` to `/tests` (it'll now always test against the installed version) * merged old regression tests into collections, e.g. `test_issue1001-1500.py` (about 90% of the regression tests are very short anyways) * tidied up and rewrote existing tests wherever possible ### Todo - [ ] move tests to `/tests` and adjust CI commands accordingly - [x] move model test suite from internal repo to `spacy-models` - [x] ~~investigate why `pipeline/test_textcat.py` is flakey~~ - [x] review old regression tests (leftover files) and see if they can be merged, simplified or deleted - [ ] update documentation on how to run tests ### Types of change enhancement, tests ## Checklist <!--- Before you submit the PR, go over this checklist and make sure you can tick off all the boxes. [] -> [x] --> - [x] I have submitted the spaCy Contributor Agreement. - [x] I ran the tests, and all new and existing tests passed. - [ ] My changes don't require a change to the documentation, or if they do, I've added all required information.
53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
# coding: utf-8
|
|
from __future__ import unicode_literals
|
|
|
|
from spacy.gold import biluo_tags_from_offsets, offsets_from_biluo_tags
|
|
from spacy.tokens import Doc
|
|
|
|
|
|
def test_gold_biluo_U(en_vocab):
|
|
orths_and_spaces = [('I', True), ('flew', True), ('to', True),
|
|
('London', False), ('.', True)]
|
|
doc = Doc(en_vocab, orths_and_spaces=orths_and_spaces)
|
|
entities = [(len("I flew to "), len("I flew to London"), 'LOC')]
|
|
tags = biluo_tags_from_offsets(doc, entities)
|
|
assert tags == ['O', 'O', 'O', 'U-LOC', 'O']
|
|
|
|
|
|
def test_gold_biluo_BL(en_vocab):
|
|
orths_and_spaces = [('I', True), ('flew', True), ('to', True), ('San', True),
|
|
('Francisco', False), ('.', True)]
|
|
doc = Doc(en_vocab, orths_and_spaces=orths_and_spaces)
|
|
entities = [(len("I flew to "), len("I flew to San Francisco"), 'LOC')]
|
|
tags = biluo_tags_from_offsets(doc, entities)
|
|
assert tags == ['O', 'O', 'O', 'B-LOC', 'L-LOC', 'O']
|
|
|
|
|
|
def test_gold_biluo_BIL(en_vocab):
|
|
orths_and_spaces = [('I', True), ('flew', True), ('to', True), ('San', True),
|
|
('Francisco', True), ('Valley', False), ('.', True)]
|
|
doc = Doc(en_vocab, orths_and_spaces=orths_and_spaces)
|
|
entities = [(len("I flew to "), len("I flew to San Francisco Valley"), 'LOC')]
|
|
tags = biluo_tags_from_offsets(doc, entities)
|
|
assert tags == ['O', 'O', 'O', 'B-LOC', 'I-LOC', 'L-LOC', 'O']
|
|
|
|
|
|
def test_gold_biluo_misalign(en_vocab):
|
|
orths_and_spaces = [('I', True), ('flew', True), ('to', True), ('San', True),
|
|
('Francisco', True), ('Valley.', False)]
|
|
doc = Doc(en_vocab, orths_and_spaces=orths_and_spaces)
|
|
entities = [(len("I flew to "), len("I flew to San Francisco Valley"), 'LOC')]
|
|
tags = biluo_tags_from_offsets(doc, entities)
|
|
assert tags == ['O', 'O', 'O', '-', '-', '-']
|
|
|
|
|
|
def test_roundtrip_offsets_biluo_conversion(en_tokenizer):
|
|
text = "I flew to Silicon Valley via London."
|
|
biluo_tags = ['O', 'O', 'O', 'B-LOC', 'L-LOC', 'O', 'U-GPE', 'O']
|
|
offsets = [(10, 24, 'LOC'), (29, 35, 'GPE')]
|
|
doc = en_tokenizer(text)
|
|
biluo_tags_converted = biluo_tags_from_offsets(doc, offsets)
|
|
assert biluo_tags_converted == biluo_tags
|
|
offsets_converted = offsets_from_biluo_tags(doc, biluo_tags)
|
|
assert offsets_converted == offsets
|