medcat.components.ner.trf.model
Classes:
-
NerModel–The NER model.
NerModel
NerModel(cat: CAT)
The NER model.
This wraps a CAT instance and simplifies its use as a NER model.
It provides methods for creating one from a TransformersNER as well as loading from a model pack (along with some validation).
It also exposes some useful parts of the CAT it wraps such as the config and the concept database.
Methods:
-
add_new_concepts–Add new concepts to the model and the concept database.
-
eval–Evaluate the underlying transformers NER model.
-
get_entities–Gets the entities recognized within a given text.
-
load_model_pack–Load NER model from model pack.
-
train–Train the underlying transformers NER model.
Attributes:
Source code in medcat-v2/medcat/components/ner/trf/model.py
26 27 | |
cat
instance-attribute
cat = cat
add_new_concepts
add_new_concepts(cui2preferred_name: dict[str, str], with_random_init: bool = False) -> None
Add new concepts to the model and the concept database.
Invoking this requires subsequent retraining on the model.
Parameters:
-
(cui2preferred_namedict[str, str]) –Dictionary where each key is the literal ID of the concept to be added and each value is its preferred name.
-
(with_random_initbool, default:False) –Whether to use the random init strategy for the new concepts. Defaults to False.
Source code in medcat-v2/medcat/components/ner/trf/model.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
eval
Evaluate the underlying transformers NER model. All the extra arguments are passed to the TransformersNER eval method. Args: json_path (Union[str, list, None]): The JSON file path to read the training data from. args: Additional arguments for TransformersNER.eval . *kwargs: Additional keyword arguments for TransformersNER.eval . Returns: Tuple[Any, Any, Any]: df, examples, dataset
Source code in medcat-v2/medcat/components/ner/trf/model.py
46 47 48 49 50 51 52 53 54 55 56 57 58 | |
get_entities
Gets the entities recognized within a given text.
The output format is identical to CAT.get_entities.
Undefined arguments and keyword arguments get passed on to CAT.get_entities.
Parameters:
-
(textstr) –The input text.
-
–*argsAdditional arguments for cat.get_entities .
-
–**kwargsAdditional keyword arguments for cat.get_entities .
Returns:
-
dict(Union[dict, Entities, OnlyCUIEntities]) –The output entities.
Source code in medcat-v2/medcat/components/ner/trf/model.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
load_model_pack
classmethod
Load NER model from model pack.
The method first wraps the loaded CAT instance.
Parameters:
-
(configOptional[dict], default:None) –Config for DeId model pack (primarily for stride of overlap window)
-
(model_pack_pathstr) –The model pack path.
Returns:
-
NerModel(NerModel) –The resulting DeI model.
Source code in medcat-v2/medcat/components/ner/trf/model.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
train
Train the underlying transformers NER model.
All the extra arguments are passed to the TransformersNER train method.
Parameters:
-
(json_pathUnion[str, list, None]) –The JSON file path to read the training data from.
-
–*argsAdditional arguments for TransformersNER.train .
-
–**kwargsAdditional keyword arguments for TransformersNER.train .
Returns:
Source code in medcat-v2/medcat/components/ner/trf/model.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |