|
5 | 5 | from hypothesis.control import assume |
6 | 6 | from hypothesis.strategies import lists, sampled_from |
7 | 7 | from transformers import BertTokenizerFast |
| 8 | +from renard.pipeline.progress import get_progress_reporter |
8 | 9 | from renard.ner_utils import NERDataset |
9 | | -from renard.pipeline.ner import ner_entities, score_ner |
| 10 | +from renard.pipeline.ner import ner_entities, score_ner, BertNamedEntityRecognizer |
10 | 11 | from renard.pipeline.ner.retrieval import ( |
11 | 12 | NERBM25ContextRetriever, |
12 | 13 | NERContextRetriever, |
@@ -34,6 +35,22 @@ def test_has_correct_number_of_entities(tokens: List[str]): |
34 | 35 | assert len(entities) == len(tokens) |
35 | 36 |
|
36 | 37 |
|
| 38 | +@pytest.mark.skipif(os.getenv("RENARD_TEST_SLOW") != "1", reason="performance") |
| 39 | +def test_run_with_context_retriever(): |
| 40 | + ner_step = BertNamedEntityRecognizer( |
| 41 | + context_retriever=NERNeighborsContextRetriever(k=2) |
| 42 | + ) |
| 43 | + ner_step._pipeline_init_(lang="eng", progress_reporter=get_progress_reporter(None)) |
| 44 | + # known crash in Renard==0.7.1 |
| 45 | + sentences = [ |
| 46 | + "Whether i shall turn out to be the hero of my own life , or whether that station will be held by anybody else , these pages must show .".split(), |
| 47 | + "To begin my life with the beginning of my life , i record that i was born ( as i have been informed and believe ) on a friday , at twelve o'clock at night .".split(), |
| 48 | + "This was the fault of Dr. Strange .".split(), |
| 49 | + ] |
| 50 | + tokens = [token for tokens in sentences for token in tokens] |
| 51 | + _ = ner_step(tokens, sentences) |
| 52 | + |
| 53 | + |
37 | 54 | @pytest.mark.skipif(os.getenv("RENARD_TEST_SLOW") != "1", reason="performance") |
38 | 55 | @pytest.mark.parametrize( |
39 | 56 | "retriever_class", [NERSamenounContextRetriever, NERBM25ContextRetriever] |
|
0 commit comments