-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdomain.py
More file actions
161 lines (117 loc) · 5.53 KB
/
Copy pathdomain.py
File metadata and controls
161 lines (117 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from enum import Enum
from typing import List, Optional, Dict, Any
from fastapi import HTTPException
from starlette.status import HTTP_400_BAD_REQUEST
from pydantic import BaseModel, Field, root_validator
class ModelType(str, Enum):
MEDCAT_SNOMED = "medcat_snomed"
MEDCAT_UMLS = "medcat_umls"
MEDCAT_ICD10 = "medcat_icd10"
MEDCAT_DEID = "medcat_deid"
ANONCAT = "anoncat"
TRANSFORMERS_DEID = "transformers_deid"
HUGGINGFACE_NER = "huggingface_ner"
class Tags(str, Enum):
Metadata = "Get the model card"
Annotations = "Retrieve NER entities by running the model"
Redaction = "Redact the extracted NER entities"
Rendering = "Preview embeddable annotation snippet in HTML"
Training = "Trigger model training on input annotations"
Evaluating = "Evaluate the deployed model with trainer export"
Authentication = "Authenticate registered users"
class TagsStreamable(str, Enum):
Streaming = "Retrieve NER entities as a stream by running the model"
class CodeType(str, Enum):
SNOMED = "SNOMED"
UMLS = "UMLS"
ICD10 = "ICD-10"
OPCS4 = "OPCS-4"
class Scope(str, Enum):
PER_CONCEPT = "per_concept"
PER_DOCUMENT = "per_document"
PER_SPAN = "per_span"
class TrainingType(str, Enum):
SUPERVISED = "supervised"
UNSUPERVISED = "unsupervised"
META_SUPERVISED = "meta_supervised"
class BuildBackend(Enum):
DOCKER = "docker build"
DOCKER_BUILDX = "docker buildx build"
class DatasetSplit(str, Enum):
TRAIN = "train"
VALIDATION = "validation"
TEST = "test"
class Device(str, Enum):
DEFAULT = "default"
CPU = "cpu"
GPU = "cuda"
MPS = "mps"
class HfTransformerBackbone(Enum):
ALBERT = "albert"
BIG_BIRD = "bert"
BERT = "bert"
DISTILBERT = "distilbert"
FUNNEL = "funnel"
LAYOUTLM = "layoutlm"
LONGFORMER = "longformer"
DEBERTA = "deberta"
MOBILEBERT = "mobilebert"
ROBERTA = "roberta"
SQUEEZEBERT = "transformer"
XLM_ROBERTA = "xlm_roberta"
class ArchiveFormat(Enum):
ZIP = "zip"
TAR_GZ = "gztar"
class TrainerBackend(Enum):
MEDCAT = "MedCAT"
TRANSFORMERS = "Transformers"
class TrackerBackend(Enum):
MLFLOW = "MLflow"
class Annotation(BaseModel):
doc_name: Optional[str] = Field(description="The name of the document to which the annotation belongs")
start: int = Field(description="The start index of the annotation span")
end: int = Field(description="The first index after the annotation span")
label_name: str = Field(description="The pretty name of the annotation concept")
label_id: str = Field(description="The code of the annotation concept")
categories: Optional[List[str]] = Field(default=None, description="The categories to which the annotation concept belongs")
accuracy: Optional[float] = Field(default=None, description="The confidence score of the annotation")
text: Optional[str] = Field(default=None, description="The string literal of the annotation span")
meta_anns: Optional[Dict] = Field(default=None, description="The meta annotations")
athena_ids: Optional[List[Dict]] = Field(default=None, description="The OHDSI Athena concept IDs")
@root_validator()
def _validate(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if values["start"] >= values["end"]:
raise HTTPException(status_code=HTTP_400_BAD_REQUEST, detail="The start index should be lower than the end index")
return values
class TextWithAnnotations(BaseModel):
text: str = Field(description="The text from which the annotations are extracted")
annotations: List[Annotation] = Field(description="The list of extracted annotations")
class TextWithPublicKey(BaseModel):
text: str = Field(description="The plain text to be sent to the model for NER and redaction")
public_key_pem: str = Field(description="the public PEM key used for encrypting detected spans")
class TextStreamItem(BaseModel):
text: str = Field(description="The text from which the annotations are extracted")
name: Optional[str] = Field(description="The name of the document containing the text")
class Config:
extra = "forbid"
class ModelCard(BaseModel):
api_version: str = Field(description="The version of the model serve APIs")
model_type: ModelType = Field(description="The type of the served model")
model_description: Optional[str] = Field(description="The description about the served model")
model_card: Optional[dict] = Field(default=None, description="The metadata of the served model")
labels: Optional[Dict[str, str]] = Field(default=None, description="The mapping of CUIs to names")
class Entity(BaseModel):
start: int = Field(description="The start index of the preview entity")
end: int = Field(description="The first index after the preview entity")
label: str = Field(description="The pretty name of the preview entity")
kb_id: str = Field(description="The knowledge base ID of the preview entity")
kb_url: str = Field(description="The knowledge base URL of the preview entity")
@root_validator()
def _validate(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if values["start"] >= values["end"]:
raise HTTPException(status_code=HTTP_400_BAD_REQUEST, detail="The start index should be lower than the end index")
return values
class Doc(BaseModel):
text: str = Field(description="The text from which the entities are extracted")
ents: List[Entity] = Field(description="The list of extracted entities")
title: Optional[str] = Field(description="The headline of the text")