cristian-untaru commited on
Commit
5ee09bf
·
verified ·
1 Parent(s): a825e7d

Update model card

Browse files
Files changed (1) hide show
  1. README.md +272 -0
README.md ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ tags:
6
+ - intent-classification
7
+ - input-guard
8
+ - medical-triage
9
+ - pre-triage
10
+ - text-classification
11
+ - scikit-learn
12
+ - tf-idf
13
+ - logistic-regression
14
+ - healthcare
15
+ - symptom-checker
16
+ - academic-project
17
+ pipeline_tag: text-classification
18
+ library_name: sklearn
19
+ model-index:
20
+ - name: sortmed-intent-classifier
21
+ results:
22
+ - task:
23
+ type: text-classification
24
+ name: Input intent classification for medical pre-triage
25
+ metrics:
26
+ - type: accuracy
27
+ value: 0.875
28
+ name: Accuracy
29
+ - type: f1
30
+ value: 0.8558
31
+ name: Macro F1
32
+ - type: precision
33
+ value: 0.8734
34
+ name: Macro Precision
35
+ - type: recall
36
+ value: 0.8634
37
+ name: Macro Recall
38
+ ---
39
+
40
+ # SortMed Intent Classifier
41
+
42
+ ## Model Description
43
+
44
+ This repository contains the intent classifier used by the **SortMed** input guard. The model decides whether a user input is a valid symptom description or whether it belongs to an unsafe or out-of-scope intent category before the text is sent to the medical triage models.
45
+
46
+ The classifier is a lightweight scikit-learn pipeline based on:
47
+
48
+ - TF-IDF text vectorization;
49
+ - Logistic Regression multi-class classification.
50
+
51
+ It is intentionally separate from the triage models. The triage models predict urgency only after this intent classifier and the deterministic input-guard rules accept the input.
52
+
53
+ This model was developed as part of the **SortMed** academic project, a medical pre-triage assistant prototype built for a bachelor's thesis by **Cristian Untaru** at the **West University of Timisoara, Faculty of Informatics**.
54
+
55
+ ## Role in SortMed
56
+
57
+ The final SortMed input validation flow is:
58
+
59
+ ```text
60
+ User input
61
+ |
62
+ v
63
+ Deterministic input-guard rules
64
+ |
65
+ v
66
+ Intent classifier
67
+ |
68
+ v
69
+ Triage model, only if intent = symptom_description
70
+ ```
71
+
72
+ The classifier is used as a semantic safety layer. It blocks prompts that may contain medical words but are not suitable symptom descriptions, such as medication requests, diagnosis requests, general medical questions, or non-medical input.
73
+
74
+ ## Intended Use
75
+
76
+ This model is intended to be used in the SortMed academic prototype for:
77
+
78
+ - classifying user input intent before medical pre-triage;
79
+ - rejecting unsafe or out-of-scope requests;
80
+ - allowing only English symptom descriptions to reach the triage classifier;
81
+ - supporting a hybrid input-guard architecture based on rules plus intent classification.
82
+
83
+ Example accepted input:
84
+
85
+ ```text
86
+ I have chest pain and I feel short of breath.
87
+ ```
88
+
89
+ Expected intent:
90
+
91
+ ```text
92
+ symptom_description
93
+ ```
94
+
95
+ Example rejected input:
96
+
97
+ ```text
98
+ Can you recommend a painkiller for my headache?
99
+ ```
100
+
101
+ Expected intent:
102
+
103
+ ```text
104
+ medication_request
105
+ ```
106
+
107
+ ## Out-of-Scope Use
108
+
109
+ This model must not be used as:
110
+
111
+ - a medical triage classifier;
112
+ - a diagnostic model;
113
+ - a medication recommendation system;
114
+ - a replacement for deterministic safety rules;
115
+ - a standalone medical safety system;
116
+ - a general-purpose moderation classifier;
117
+ - a multilingual intent classifier without additional validation.
118
+
119
+ The model only classifies intent. It does not assess symptom severity and does not provide medical advice.
120
+
121
+ ## Intent Classes
122
+
123
+ | Intent class | Meaning | SortMed behavior |
124
+ |---|---|---|
125
+ | `symptom_description` | The user describes symptoms or how they feel. | Accepted for triage if the confidence is high enough. |
126
+ | `medication_request` | The user asks for medication, drugs, treatment, or dosage advice. | Rejected with a medication-specific safety message. |
127
+ | `diagnosis_request` | The user asks directly for a diagnosis or condition identification. | Rejected with a diagnosis-specific safety message. |
128
+ | `general_medical_question` | The user asks a general medical question instead of describing symptoms. | Rejected with a message asking for a symptom description. |
129
+ | `non_medical` | The input is unrelated to medical symptoms. | Rejected as out of scope. |
130
+
131
+ Only `symptom_description` is considered a valid intent for continuing to the triage models.
132
+
133
+ ## Configuration
134
+
135
+ The published configuration is stored in [`intent_config.json`](./intent_config.json).
136
+
137
+ | Field | Value |
138
+ |---|---:|
139
+ | Model type | `tfidf+logreg` |
140
+ | Number of classes | 5 |
141
+ | Valid triage intent | `symptom_description` |
142
+ | General confidence threshold | 0.5 |
143
+ | TF-IDF feature count | 1936 |
144
+ | Training examples | 382 |
145
+ | Test examples | 96 |
146
+ | scikit-learn version | `1.6.1` |
147
+
148
+ In the SortMed backend, `symptom_description` is accepted only when it passes the valid-intent confidence threshold used by the input guard. Other intents are rejected with class-specific user-facing messages.
149
+
150
+ ## Evaluation Results
151
+
152
+ The classifier was evaluated on the held-out test split.
153
+
154
+ | Metric | Test Score |
155
+ |---|---:|
156
+ | Accuracy | 0.8750 |
157
+ | Macro Precision | 0.8734 |
158
+ | Macro Recall | 0.8634 |
159
+ | Macro F1 | 0.8558 |
160
+
161
+ The confusion matrix is available in [`intent_confusion_matrix.png`](./intent_confusion_matrix.png).
162
+
163
+ ## How to Use
164
+
165
+ ```python
166
+ from huggingface_hub import hf_hub_download
167
+ import joblib
168
+ import json
169
+
170
+ repo_id = "cristian-untaru/sortmed-intent-classifier"
171
+
172
+ model_path = hf_hub_download(repo_id=repo_id, filename="intent_pipeline.joblib")
173
+ config_path = hf_hub_download(repo_id=repo_id, filename="intent_config.json")
174
+
175
+ pipeline = joblib.load(model_path)
176
+
177
+ with open(config_path, "r", encoding="utf-8") as file:
178
+ config = json.load(file)
179
+
180
+ text = "I have chest pain and I feel short of breath."
181
+
182
+ probabilities = pipeline.predict_proba([text])[0]
183
+ classes = list(pipeline.classes_)
184
+ best_index = probabilities.argmax()
185
+
186
+ intent = classes[best_index]
187
+ confidence = float(probabilities[best_index])
188
+
189
+ print("Intent:", intent)
190
+ print("Confidence:", round(confidence, 4))
191
+ print("Valid intent:", config["valid_intent"])
192
+ ```
193
+
194
+ Security note: `joblib` files rely on Python pickle serialization. Load this artifact only from trusted sources.
195
+
196
+ ## Repository Files
197
+
198
+ | File | Description |
199
+ |---|---|
200
+ | `intent_pipeline.joblib` | Serialized scikit-learn TF-IDF + Logistic Regression pipeline. |
201
+ | `intent_config.json` | Intent classes, accepted intent, thresholds, feature count, split sizes, and scikit-learn version. |
202
+ | `intent_test_metrics.json` | Held-out test metrics for the intent classifier. |
203
+ | `intent_confusion_matrix.png` | Confusion matrix image for the intent classification task. |
204
+ | `README.md` | Model card documentation. |
205
+ | `.gitattributes` | Git LFS configuration for large files. |
206
+
207
+ ## Limitations
208
+
209
+ This model has several important limitations:
210
+
211
+ - It is a TF-IDF + Logistic Regression classifier, not a contextual transformer or LLM.
212
+ - It may be sensitive to wording, spelling, unusual phrasing, or adversarial inputs.
213
+ - It was trained for English input only.
214
+ - It does not perform medical triage or diagnosis.
215
+ - It does not detect emergency severity.
216
+ - It should be used together with deterministic input validation rules.
217
+ - It should not be treated as a standalone safety system.
218
+
219
+ ## Ethical and Safety Considerations
220
+
221
+ Input guards for medical applications must be conservative. This classifier is designed to reduce unsafe routing into the triage models, but it cannot guarantee perfect rejection of every invalid prompt.
222
+
223
+ For this reason, SortMed uses a hybrid validation design:
224
+
225
+ - deterministic rules for empty, repetitive, non-English, malformed, or adversarial input;
226
+ - this intent classifier for semantic request type detection;
227
+ - triage models only after the input is accepted as a symptom description.
228
+
229
+ Any production medical system would require clinical review, larger safety testing, monitoring, and a stronger risk-management process.
230
+
231
+ ## Medical Disclaimer
232
+
233
+ This model is part of an academic prototype. It does not provide medical advice, diagnosis, treatment, or emergency triage.
234
+
235
+ If symptoms are severe, sudden, worsening, or potentially life-threatening, users should contact emergency services or a qualified healthcare professional immediately.
236
+
237
+ ## Related SortMed Resources
238
+
239
+ ### Triage Models
240
+
241
+ ### Full Fine-Tuned Models
242
+
243
+ - [`cristian-untaru/distilbert-medical-triage`](https://huggingface.co/cristian-untaru/distilbert-medical-triage)
244
+ - [`cristian-untaru/biobert-medical-triage`](https://huggingface.co/cristian-untaru/biobert-medical-triage)
245
+ - [`cristian-untaru/roberta-medical-triage`](https://huggingface.co/cristian-untaru/roberta-medical-triage)
246
+ - [`cristian-untaru/biomedbert-medical-triage`](https://huggingface.co/cristian-untaru/biomedbert-medical-triage)
247
+
248
+ ### LoRA Models
249
+
250
+ - [`cristian-untaru/lora-distilbert-medical-triage`](https://huggingface.co/cristian-untaru/lora-distilbert-medical-triage)
251
+ - [`cristian-untaru/lora-biobert-medical-triage`](https://huggingface.co/cristian-untaru/lora-biobert-medical-triage)
252
+ - [`cristian-untaru/lora-roberta-medical-triage`](https://huggingface.co/cristian-untaru/lora-roberta-medical-triage)
253
+ - [`cristian-untaru/lora-biomedbert-medical-triage`](https://huggingface.co/cristian-untaru/lora-biomedbert-medical-triage)
254
+
255
+ ### Bottleneck MLP Adapter Models
256
+
257
+ - [`cristian-untaru/bottleneck-mlp-distilbert-medical-triage`](https://huggingface.co/cristian-untaru/bottleneck-mlp-distilbert-medical-triage)
258
+ - [`cristian-untaru/bottleneck-mlp-biobert-medical-triage`](https://huggingface.co/cristian-untaru/bottleneck-mlp-biobert-medical-triage)
259
+ - [`cristian-untaru/bottleneck-mlp-roberta-medical-triage`](https://huggingface.co/cristian-untaru/bottleneck-mlp-roberta-medical-triage)
260
+ - [`cristian-untaru/bottleneck-mlp-biomedbert-medical-triage`](https://huggingface.co/cristian-untaru/bottleneck-mlp-biomedbert-medical-triage)
261
+
262
+ ### Frozen Encoder Models
263
+
264
+ - [`cristian-untaru/frozen-encoder-distilbert-medical-triage`](https://huggingface.co/cristian-untaru/frozen-encoder-distilbert-medical-triage)
265
+ - [`cristian-untaru/frozen-encoder-biobert-medical-triage`](https://huggingface.co/cristian-untaru/frozen-encoder-biobert-medical-triage)
266
+ - [`cristian-untaru/frozen-encoder-roberta-medical-triage`](https://huggingface.co/cristian-untaru/frozen-encoder-roberta-medical-triage)
267
+ - [`cristian-untaru/frozen-encoder-biomedbert-medical-triage`](https://huggingface.co/cristian-untaru/frozen-encoder-biomedbert-medical-triage)
268
+
269
+ ### Datasets
270
+
271
+ - [`cristian-untaru/symcat-medical-triage-dataset`](https://huggingface.co/datasets/cristian-untaru/symcat-medical-triage-dataset)
272
+ - [`cristian-untaru/medquad-retrieval-pretriage`](https://huggingface.co/datasets/cristian-untaru/medquad-retrieval-pretriage)