Skip to content

edsnlp.pipelines.trainable.nested_ner.factory

create_component(nlp, name, model, ent_labels=None, spans_labels=None, scorer=None)

Initialize a general named entity recognizer (with or without nested or overlapping entities).

PARAMETER DESCRIPTION
nlp

The current nlp object

TYPE: Language

name

Name of the component

TYPE: str

model

The model to extract the spans

TYPE: Model

ent_labels

list of labels to filter entities for in doc.ents

DEFAULT: None

spans_labels

Mapping from span group names to list of labels to look for entities and assign the predicted entities

DEFAULT: None

scorer

Method to call to score predictions

DEFAULT: None

Source code in edsnlp/pipelines/trainable/nested_ner/factory.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@Language.factory(
    "nested_ner",
    default_config=NESTED_NER_DEFAULTS,
    requires=["doc.ents", "doc.spans"],
    assigns=["doc.ents", "doc.spans"],
    default_score_weights={
        "ents_f": 1.0,
        "ents_p": 0.0,
        "ents_r": 0.0,
    },
)
def create_component(
    nlp: Language,
    name: str,
    model: Model,
    ent_labels=None,
    spans_labels=None,
    scorer=None,
):
    """
    Initialize a general named entity recognizer (with or without nested or
    overlapping entities).

    Parameters
    ----------
    nlp: Language
        The current nlp object
    name: str
        Name of the component
    model: Model
        The model to extract the spans
    ent_labels: Iterable[str]
        list of labels to filter entities for in `doc.ents`
    spans_labels: Mapping[str, Iterable[str]]
        Mapping from span group names to list of labels to look for entities
        and assign the predicted entities
    scorer: Optional[Callable]
        Method to call to score predictions
    """
    return TrainableNer(
        vocab=nlp.vocab,
        model=model,
        name=name,
        ent_labels=ent_labels,
        spans_labels=spans_labels,
        scorer=scorer,
    )