SpacyEntityRecognizer

Create an EntityRecognizer from a spaCy Langauge instance

labels: List[str] (property, readonly)

Return List of spaCy ner labels

Returns

Type Description
List[str] List[str]: List of labels from spaCy ner pipe

__init__(self, nlp)

Show source code in recon/recognizer.py
46
47
48
49
50
51
52
53
    def __init__(self, nlp: Language):
        """Initialize a SpacyEntityRecognizer

        Args:
            nlp (Language): spaCy Language instance that can sets doc.ents
        """
        super().__init__()
        self.nlp = nlp

Initialize a SpacyEntityRecognizer

Parameters

Name Type Description Default
nlp Language spaCy Language instance that can sets doc.ents required

predict(self, texts)

Show source code in recon/recognizer.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
    def predict(self, texts: Iterable[str]) -> Iterator[Example]:
        """Run spaCy nlp.pipe on a batch of raw texts.

        Args:
            texts (Iterable[str]): Raw text examples

        Yields:
            Iterator[Example]: Examples constructed from spaCy Model predictions
        """
        examples: List[Example] = []

        for doc in self.nlp.pipe(texts):
            yield Example(
                text=doc.text,
                spans=[
                    Span(
                        text=e.text,
                        start=e.start_char,
                        end=e.end_char,
                        label=e.label_,
                        token_start=e.start,
                        token_end=e.end,
                    )
                    for e in doc.ents
                ],
                tokens=[Token(text=t.text, start=t.idx, end=t.idx + len(t), id=t.i) for t in doc],
            )

Run spaCy nlp.pipe on a batch of raw texts.

Parameters

Name Type Description Default
texts Iterable[str] Raw text examples required

Yields: Iterator[Example]: Examples constructed from spaCy Model predictions