Skip to content

Commit 668e5b3

Browse files
committed
api: Include labels in DeID service model card
Extend the base model card schema to allow passing a mapping of labels, i.e. concept IDs (e.g. CUIs) to names. This is particularly useful when using the MedCAT model DeID service, which is typically configured to serve models with a relatively small CDB that can be exposed in its entirety as part of the model card. This information can be interesting to the user (or client application), providing insight into the concepts that the model is capable of identifying and by extension enabling them to decide and control which of them should be redacted. The 'labels' field is always included in the API's responses when the '/info' endpoint is called, but is only populated with the mapping in a dict format when the CMS instance is configured to use the MedCAT model DeID service. Signed-off-by: Phoevos Kalemkeris <phoevos.kalemkeris@ucl.ac.uk>
1 parent 4fcb576 commit 668e5b3

File tree

5 files changed

+6
-0
lines changed

5 files changed

+6
-0
lines changed

app/domain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class ModelCard(BaseModel):
138138
model_type: ModelType = Field(description="The type of the served model")
139139
model_description: Optional[str] = Field(description="The description about the served model")
140140
model_card: Optional[dict] = Field(default=None, description="The metadata of the served model")
141+
labels: Optional[Dict[str, str]] = Field(default=None, description="The mapping of CUIs to names")
141142

142143

143144
class Entity(BaseModel):

app/model_services/medcat_model_deid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def info(self) -> ModelCard:
6969
model_type=ModelType.ANONCAT,
7070
api_version=self.api_version,
7171
model_card=model_card,
72+
labels=self.model.cdb.cui2preferred_name,
7273
)
7374

7475
def annotate(self, text: str) -> List[Annotation]:

tests/app/api/test_serving_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def test_train_unsupervised_with_hf_hub_dataset(model_service, client):
345345
"model_description": "huggingface_ner_model_description",
346346
"model_type": ModelType.MEDCAT_SNOMED,
347347
"model_card": None,
348+
"labels": None,
348349
})
349350
model_service.info.return_value = model_card
350351
model_service.train_unsupervised.return_value = (True, "experiment_id", "run_id")

tests/app/api/test_serving_hf_ner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_train_unsupervised_with_hf_hub_dataset(model_service, client):
4242
"model_description": "huggingface_ner_model_description",
4343
"model_type": ModelType.HUGGINGFACE_NER,
4444
"model_card": None,
45+
"labels": None,
4546
})
4647
model_service.info.return_value = model_card
4748
model_service.train_unsupervised.return_value = (True, "experiment_id", "run_id")

tests/app/api/test_serving_trf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_readyz(model_service, client):
3737
"model_description": "deid_model_description",
3838
"model_type": ModelType.TRANSFORMERS_DEID,
3939
"model_card": None,
40+
"labels": None,
4041
})
4142
model_service.info.return_value = model_card
4243

@@ -49,6 +50,7 @@ def test_info(model_service, client):
4950
"model_description": "deid_model_description",
5051
"model_type": ModelType.TRANSFORMERS_DEID,
5152
"model_card": None,
53+
"labels": None,
5254
})
5355
model_service.info.return_value = model_card
5456

0 commit comments

Comments
 (0)