Update vips_classifier.py
Browse files- vips_classifier.py +211 -415
vips_classifier.py
CHANGED
|
@@ -1,415 +1,211 @@
|
|
| 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 |
-
1.
|
| 83 |
-
2.
|
| 84 |
-
3.
|
| 85 |
-
4.
|
| 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 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
#
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
- كم جهد بذلت لإنجاز المهمة؟
|
| 213 |
-
- **0** = جهد قليل جداً
|
| 214 |
-
- **100** = جهد كبير جداً
|
| 215 |
-
|
| 216 |
-
#### **6. Frustration (الإحباط)**
|
| 217 |
-
- هل شعرت بالإحباط؟
|
| 218 |
-
- **0** = لا إحباط أبداً
|
| 219 |
-
- **100** = إحباط شديد
|
| 220 |
-
|
| 221 |
-
### **كيف يُحسب؟**
|
| 222 |
-
|
| 223 |
-
```
|
| 224 |
-
NASA-TLX Score = (D1 + D2 + D3 + D4 + D5 + D6) / 6
|
| 225 |
-
```
|
| 226 |
-
|
| 227 |
-
### **مثال حساب:**
|
| 228 |
-
|
| 229 |
-
| البُعد | النقاط |
|
| 230 |
-
|--------|--------|
|
| 231 |
-
| Mental Demand | 30 |
|
| 232 |
-
| Physical Demand | 10 |
|
| 233 |
-
| Temporal Demand | 20 |
|
| 234 |
-
| Performance | 15 |
|
| 235 |
-
| Effort | 25 |
|
| 236 |
-
| Frustration | 10 |
|
| 237 |
-
|
| 238 |
-
```
|
| 239 |
-
NASA-TLX = (30 + 10 + 20 + 15 + 25 + 10) / 6
|
| 240 |
-
= 110 / 6
|
| 241 |
-
= 18.3 (ممتاز!)
|
| 242 |
-
```
|
| 243 |
-
|
| 244 |
-
### **تفسير النتائج:**
|
| 245 |
-
|
| 246 |
-
| النتيجة | التقدير | التفسير |
|
| 247 |
-
|---------|---------|---------|
|
| 248 |
-
| **0-25** | 🟢 Mycket låg | ممتاز! حمل معرفي منخفض جداً |
|
| 249 |
-
| **26-40** | 🔵 Låg | جيد - **مقبول للاستخدام السريري** |
|
| 250 |
-
| **41-60** | 🟡 Måttlig | متوسط - يحتاج بعض التحسينات |
|
| 251 |
-
| **61-100** | 🔴 Hög | عالي - غير مقبول |
|
| 252 |
-
|
| 253 |
-
### **للأطروحة:**
|
| 254 |
-
```
|
| 255 |
-
تم تقييم الحمل المعرفي باستخدام NASA-TLX (Hart & Staveland, 1988).
|
| 256 |
-
النتيجة: 18.3 (Mycket låg belastning)
|
| 257 |
-
هذا أقل بكثير من الحد الأقصى المقبول (40).
|
| 258 |
-
```
|
| 259 |
-
|
| 260 |
-
---
|
| 261 |
-
|
| 262 |
-
## 📊 **استخدام الاستبيانين معاً في البحث**
|
| 263 |
-
|
| 264 |
-
### **التوقيت الموصى به:**
|
| 265 |
-
|
| 266 |
-
#### **المرحلة 1: قبل الاختبار**
|
| 267 |
-
- شرح النظام للمشاركين
|
| 268 |
-
- تدريب قصير (5 دقائق)
|
| 269 |
-
|
| 270 |
-
#### **المرحلة 2: الاختبار**
|
| 271 |
-
- استخدم النظام لـ 3-5 سيناريوهات
|
| 272 |
-
- دع المشارك يستكشف ب��رية
|
| 273 |
-
|
| 274 |
-
#### **المرحلة 3: بعد الاختبار فوراً**
|
| 275 |
-
- املأ NASA-TLX (الانطباع الفوري)
|
| 276 |
-
- املأ SUS (التقييم العام)
|
| 277 |
-
|
| 278 |
-
### **عدد المشاركين:**
|
| 279 |
-
|
| 280 |
-
| الاستبيان | الحد الأدنى | الموصى به |
|
| 281 |
-
|-----------|-------------|-----------|
|
| 282 |
-
| **SUS** | 5 مشاركين | **8-12 مشارك** |
|
| 283 |
-
| **NASA-TLX** | 5 مشاركين | **8-12 مشارك** |
|
| 284 |
-
|
| 285 |
-
### **تحليل النتائج:**
|
| 286 |
-
|
| 287 |
-
#### **SUS:**
|
| 288 |
-
```excel
|
| 289 |
-
=AVERAGE(Participant1_SUS, Participant2_SUS, ..., Participant10_SUS)
|
| 290 |
-
=STDEV(Participant1_SUS, Participant2_SUS, ..., Participant10_SUS)
|
| 291 |
-
```
|
| 292 |
-
|
| 293 |
-
**مثال:**
|
| 294 |
-
- المتوسط: 82.5
|
| 295 |
-
- الانحراف المعياري: 8.3
|
| 296 |
-
- **النتيجة**: "متوسط SUS كان 82.5 (SD=8.3)، وهو أعلى من الحد الأدنى المقبول (70)"
|
| 297 |
-
|
| 298 |
-
#### **NASA-TLX:**
|
| 299 |
-
```excel
|
| 300 |
-
=AVERAGE(Participant1_TLX, Participant2_TLX, ..., Participant10_TLX)
|
| 301 |
-
=STDEV(Participant1_TLX, Participant2_TLX, ..., Participant10_TLX)
|
| 302 |
-
```
|
| 303 |
-
|
| 304 |
-
**مثال:**
|
| 305 |
-
- المتوسط: 22.7
|
| 306 |
-
- الانحراف المعياري: 5.2
|
| 307 |
-
- **النتيجة**: "متوسط NASA-TLX كان 22.7 (SD=5.2)، وهو أقل من الحد الأقصى المقبول (40)"
|
| 308 |
-
|
| 309 |
-
---
|
| 310 |
-
|
| 311 |
-
## 📂 **هيكل التابات الجديد:**
|
| 312 |
-
|
| 313 |
-
```
|
| 314 |
-
🏥 VoiceNote AI
|
| 315 |
-
├── 🎤 Tab 1: Röstinspelning (تقنية واحدة)
|
| 316 |
-
├── ⌨️ Tab 2: Textinmatning (تقنية واحدة)
|
| 317 |
-
├── 🔬 Tab 3: Jämförelse (3 تقنيات معاً!) ← جديد!
|
| 318 |
-
├── ℹ️ Tab 4: Instruktioner
|
| 319 |
-
├── 📊 Tab 5: SUS Utvärdering ← جديد!
|
| 320 |
-
└── 🧠 Tab 6: NASA-TLX Utvärdering ← جديد!
|
| 321 |
-
```
|
| 322 |
-
|
| 323 |
-
---
|
| 324 |
-
|
| 325 |
-
## 🚀 **بروتوكول البحث الكامل:**
|
| 326 |
-
|
| 327 |
-
### **الأسبوع 1-2: اختبار التقنيات**
|
| 328 |
-
- Zero-shot: 20 سيناريو
|
| 329 |
-
- Few-shot: 20 سيناريو
|
| 330 |
-
- Chain-of-Thought: 20 سيناريو
|
| 331 |
-
- **استخدم Tab 3 للمقارنة المباشرة!**
|
| 332 |
-
|
| 333 |
-
### **الأسبوع 3: تقييم المستخدمين**
|
| 334 |
-
- 10 مشاركين
|
| 335 |
-
- كل مشارك:
|
| 336 |
-
- يستخدم النظام (15 دقيقة)
|
| 337 |
-
- يملأ SUS (5 دقائق)
|
| 338 |
-
- يملأ NASA-TLX (5 دقائق)
|
| 339 |
-
|
| 340 |
-
### **الأسبوع 4: التحليل والكتابة**
|
| 341 |
-
- تحليل نتائج التقنيات
|
| 342 |
-
- حساب SUS و NASA-TLX
|
| 343 |
-
- كتابة الأطروحة
|
| 344 |
-
|
| 345 |
-
---
|
| 346 |
-
|
| 347 |
-
## 📝 **قالب قسم النتائج:**
|
| 348 |
-
|
| 349 |
-
```markdown
|
| 350 |
-
5.3 تقييم قابلية الاستخدام
|
| 351 |
-
|
| 352 |
-
5.3.1 System Usability Scale (SUS)
|
| 353 |
-
شارك 10 مستخدمين (8 ممرضات، 2 طلاب تمريض) في تقييم النظام باستخدام SUS.
|
| 354 |
-
متوسط النتيجة كان 82.5 (SD=8.3)، وهو أعلى من الحد الأدنى المقبول البالغ 70.
|
| 355 |
-
هذا يصنف النظام كـ "Good" (Grade B) ويشير إلى قابلية استخدام جيدة للتطبيق السريري.
|
| 356 |
-
|
| 357 |
-
5.3.2 NASA Task Load Index (NASA-TLX)
|
| 358 |
-
متوسط الحمل المعرفي كان 22.7 (SD=5.2)، وهو أقل بكثير من الحد الأقصى المقبول (40).
|
| 359 |
-
أعلى الأبعاد كانت Mental Demand (30.5) و Effort (28.3).
|
| 360 |
-
أقل الأبعاد كانت Physical Demand (12.1) و Frustration (15.8).
|
| 361 |
-
النتائج تشير إلى أن النظام سهل الاستخدام ولا يسبب إجهاد معرفي كبير.
|
| 362 |
-
```
|
| 363 |
-
|
| 364 |
-
---
|
| 365 |
-
|
| 366 |
-
## 🎯 **المراجع للاستبيانات:**
|
| 367 |
-
|
| 368 |
-
### **SUS:**
|
| 369 |
-
```
|
| 370 |
-
Brooke, J. (1996). SUS: A "quick and dirty" usability scale.
|
| 371 |
-
In P. W. Jordan, B. Thomas, B. A. Weerdmeester, & I. L. McClelland (Eds.),
|
| 372 |
-
Usability Evaluation in Industry (pp. 189-194). London: Taylor & Francis.
|
| 373 |
-
```
|
| 374 |
-
|
| 375 |
-
### **NASA-TLX:**
|
| 376 |
-
```
|
| 377 |
-
Hart, S. G., & Staveland, L. E. (1988). Development of NASA-TLX (Task Load Index):
|
| 378 |
-
Results of empirical and theoretical research.
|
| 379 |
-
In P. A. Hancock & N. Meshkati (Eds.),
|
| 380 |
-
Human Mental Workload (pp. 139-183). Amsterdam: North-Holland.
|
| 381 |
-
```
|
| 382 |
-
|
| 383 |
-
---
|
| 384 |
-
|
| 385 |
-
## ✅ **Checklist قبل البدء:**
|
| 386 |
-
|
| 387 |
-
- [ ] تأكد من تحديث جميع الملفات على HuggingFace
|
| 388 |
-
- [ ] اختبر Tab 3 (المقارنة) مع نص قصير
|
| 389 |
-
- [ ] جرب SUS واملأه لنفسك
|
| 390 |
-
- [ ] جرب NASA-TLX واملأه لنفسك
|
| 391 |
-
- [ ] خذ screenshots لكل tab
|
| 392 |
-
- [ ] جهز 20 سيناريو للاختبار
|
| 393 |
-
- [ ] جهز نموذج Excel لـ SUS و NASA-TLX
|
| 394 |
-
- [ ] ابحث عن 10 مشاركين
|
| 395 |
-
|
| 396 |
-
---
|
| 397 |
-
|
| 398 |
-
## 🎊 **ملخص الميزات الجديدة:**
|
| 399 |
-
|
| 400 |
-
### **ما كان موجوداً:**
|
| 401 |
-
- ✅ 2 تقنيات (Few-shot, Chain-of-Thought)
|
| 402 |
-
- ✅ تاب واحد لكل تقنية
|
| 403 |
-
- ✅ لا استبيانات
|
| 404 |
-
|
| 405 |
-
### **ما أصبح موجوداً الآن:**
|
| 406 |
-
- ✅ **3 تقنيات** (Zero-shot, Few-shot, Chain-of-Thought)
|
| 407 |
-
- ✅ **تاب المقارنة** - يشغل 3 تقنيات معاً!
|
| 408 |
-
- ✅ **استبيان SUS** - قياس قابلية الاستخدام
|
| 409 |
-
- ✅ **استبيان NASA-TLX** - قياس الحمل المعرفي
|
| 410 |
-
- ✅ **جداول مقارنة** - نتائج جنباً إلى جنب
|
| 411 |
-
- ✅ **رسوم بيانية** - bars للـ NASA-TLX
|
| 412 |
-
|
| 413 |
-
---
|
| 414 |
-
|
| 415 |
-
**🚀 كل شيء جاهز للبحث الآن! حمّل الملفات وابدأ!** 🎓✨📊
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
VoiceNote AI - VIPS Classifier
|
| 3 |
+
Classifies patient information into VIPS categories using prompt engineering
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import logging
|
| 7 |
+
from config import Config, VIPS_CATEGORIES
|
| 8 |
+
from gdpr_filter import apply_dual_layer_gdpr
|
| 9 |
+
|
| 10 |
+
logger = logging.getLogger(__name__)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def build_prompt_zero_shot(text: str) -> str:
|
| 14 |
+
"""
|
| 15 |
+
Build Zero-shot prompting without any examples
|
| 16 |
+
|
| 17 |
+
Reference: Sivarajkumar et al. (2022) - HealthPrompt: Zero-shot Learning
|
| 18 |
+
"""
|
| 19 |
+
prompt = f"""Du är en AI-assistent som hjälper sjuksköterskor att strukturera journalanteckningar enligt VIPS-modellen.
|
| 20 |
+
|
| 21 |
+
VIPS står för:
|
| 22 |
+
- V (Välbefinnande): Fysiska och psykiska symtom, smärta, känslor
|
| 23 |
+
- I (Integritet): Vanor, preferenser, sociala relationer
|
| 24 |
+
- P (Prevention): Förebyggande åtgärder, hälsofrämjande aktiviteter
|
| 25 |
+
- S (Säkerhet): Risker, läkemedel, säkerhetsåtgärder
|
| 26 |
+
|
| 27 |
+
VIKTIGA REGLER:
|
| 28 |
+
1. Om det INTE finns relevant information för en kategori, skriv "Ingen relevant information."
|
| 29 |
+
2. Skriv INTE tomma platshållare eller "[NAMN]" om det inte finns information
|
| 30 |
+
3. Var kortfattad och professionell
|
| 31 |
+
4. Dokumentera endast det som faktiskt sagts
|
| 32 |
+
|
| 33 |
+
Patientens berättelse:
|
| 34 |
+
"{text}"
|
| 35 |
+
|
| 36 |
+
Klassificera informationen enligt VIPS-format (V, I, P, S).
|
| 37 |
+
|
| 38 |
+
Output:"""
|
| 39 |
+
|
| 40 |
+
return prompt
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def build_prompt_few_shot(text: str) -> str:
|
| 44 |
+
"""
|
| 45 |
+
Build Few-shot prompting with 3 concrete examples
|
| 46 |
+
|
| 47 |
+
Reference: Brown et al. (2020) - Language Models are Few-Shot Learners
|
| 48 |
+
"""
|
| 49 |
+
prompt = f"""Du är en AI-assistent som hjälper sjuksköterskor att strukturera journalanteckningar enligt VIPS-modellen.
|
| 50 |
+
|
| 51 |
+
VIPS står för:
|
| 52 |
+
- V (Välbefinnande): Fysiska och psykiska symtom, smärta, känslor
|
| 53 |
+
- I (Integritet): Vanor, preferenser, sociala relationer
|
| 54 |
+
- P (Prevention): Förebyggande åtgärder, hälsofrämjande aktiviteter
|
| 55 |
+
- S (Säkerhet): Risker, läkemedel, säkerhetsåtgärder
|
| 56 |
+
|
| 57 |
+
EXEMPEL 1:
|
| 58 |
+
Input: "Jag har ont i huvudet och känner mig trött."
|
| 59 |
+
Output:
|
| 60 |
+
V: Patienten rapporterar huvudvärk och trötthet.
|
| 61 |
+
I: Ingen relevant information.
|
| 62 |
+
P: Ingen relevant information.
|
| 63 |
+
S: Ingen relevant information.
|
| 64 |
+
|
| 65 |
+
EXEMPEL 2:
|
| 66 |
+
Input: "Jag tar Metoprolol dagligen och röker 10 cigaretter per dag."
|
| 67 |
+
Output:
|
| 68 |
+
V: Ingen relevant information.
|
| 69 |
+
I: Patienten röker 10 cigaretter dagligen.
|
| 70 |
+
P: Rökavvänjning kan diskuteras.
|
| 71 |
+
S: Patienten tar Metoprolol dagligen.
|
| 72 |
+
|
| 73 |
+
EXEMPEL 3:
|
| 74 |
+
Input: "Jag har ont i bröstet, känner mig yr, och har svårt att andas."
|
| 75 |
+
Output:
|
| 76 |
+
V: Patienten rapporterar bröstsmärta, yrsel och andningssvårigheter.
|
| 77 |
+
I: Ingen relevant information.
|
| 78 |
+
P: Ingen relevant information.
|
| 79 |
+
S: Akuta symtom som kräver omedelbar bedömning.
|
| 80 |
+
|
| 81 |
+
VIKTIGA REGLER:
|
| 82 |
+
1. Om det INTE finns relevant information för en kategori, skriv "Ingen relevant information."
|
| 83 |
+
2. Skriv INTE tomma platshållare eller "[NAMN]" om det inte finns information
|
| 84 |
+
3. Var kortfattad och professionell
|
| 85 |
+
4. Dokumentera endast det som faktiskt sagts
|
| 86 |
+
|
| 87 |
+
NU ÄR DET DIN TUR:
|
| 88 |
+
Input: "{text}"
|
| 89 |
+
|
| 90 |
+
Ge ENDAST svaret i VIPS-format.
|
| 91 |
+
|
| 92 |
+
Output:"""
|
| 93 |
+
|
| 94 |
+
return prompt
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def build_prompt_chain_of_thought(text: str) -> str:
|
| 98 |
+
"""
|
| 99 |
+
Build Chain-of-Thought prompting with step-by-step reasoning
|
| 100 |
+
|
| 101 |
+
Reference: Wei et al. (2022) - Chain-of-Thought Prompting Elicits Reasoning
|
| 102 |
+
"""
|
| 103 |
+
prompt = f"""Du är en AI-assistent som hjälper sjuksköterskor att strukturera journalanteckningar enligt VIPS-modellen.
|
| 104 |
+
|
| 105 |
+
VIPS står för:
|
| 106 |
+
- V (Välbefinnande): Fysiska och psykiska symtom, smärta, känslor
|
| 107 |
+
- I (Integritet): Vanor, preferenser, sociala relationer
|
| 108 |
+
- P (Prevention): Förebyggande åtgärder, hälsofrämjande aktiviteter
|
| 109 |
+
- S (Säkerhet): Risker, läkemedel, säkerhetsåtgärder
|
| 110 |
+
|
| 111 |
+
STEG-FÖR-STEG ANALYS:
|
| 112 |
+
|
| 113 |
+
Följ dessa steg för att klassificera informationen:
|
| 114 |
+
|
| 115 |
+
Steg 1: Läs patientens berättelse noggrant
|
| 116 |
+
Steg 2: Identifiera alla symtom och känslor → placera under V
|
| 117 |
+
Steg 3: Identifiera vanor och preferenser → placera under I
|
| 118 |
+
Steg 4: Identifiera förebyggande åtgärder → placera under P
|
| 119 |
+
Steg 5: Identifiera risker och läkemedel → placera under S
|
| 120 |
+
|
| 121 |
+
Patientens berättelse:
|
| 122 |
+
"{text}"
|
| 123 |
+
|
| 124 |
+
VIKTIGA REGLER:
|
| 125 |
+
1. Om det INTE finns relevant information för en kategori, skriv "Ingen relevant information."
|
| 126 |
+
2. Skriv INTE tomma platshållare eller "[NAMN]" om det inte finns information
|
| 127 |
+
3. Var kortfattad och professionell
|
| 128 |
+
4. Dokumentera endast det som faktiskt sagts
|
| 129 |
+
|
| 130 |
+
Analysera texten steg för steg och ge sedan svaret i VIPS-format.
|
| 131 |
+
|
| 132 |
+
Output:"""
|
| 133 |
+
|
| 134 |
+
return prompt
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def classify_vips(text: str, mistral_client) -> dict:
|
| 138 |
+
"""
|
| 139 |
+
Classify text into VIPS categories
|
| 140 |
+
|
| 141 |
+
Args:
|
| 142 |
+
text: Input text to classify
|
| 143 |
+
mistral_client: Mistral AI client instance
|
| 144 |
+
|
| 145 |
+
Returns:
|
| 146 |
+
Dictionary with VIPS classifications
|
| 147 |
+
"""
|
| 148 |
+
# Apply GDPR Layer 1: Anonymize input
|
| 149 |
+
anonymized_input, _ = apply_dual_layer_gdpr(text, "")
|
| 150 |
+
|
| 151 |
+
# Select prompt technique
|
| 152 |
+
technique = Config.PROMPT_TECHNIQUE
|
| 153 |
+
logger.info(f"Using {technique} prompting")
|
| 154 |
+
|
| 155 |
+
if technique == "zero_shot":
|
| 156 |
+
prompt = build_prompt_zero_shot(anonymized_input)
|
| 157 |
+
max_tokens = Config.LLM_MAX_TOKENS_FEW_SHOT # Same as few-shot
|
| 158 |
+
elif technique == "few_shot":
|
| 159 |
+
prompt = build_prompt_few_shot(anonymized_input)
|
| 160 |
+
max_tokens = Config.LLM_MAX_TOKENS_FEW_SHOT
|
| 161 |
+
else: # chain_of_thought
|
| 162 |
+
prompt = build_prompt_chain_of_thought(anonymized_input)
|
| 163 |
+
max_tokens = Config.LLM_MAX_TOKENS_CHAIN_OF_THOUGHT
|
| 164 |
+
|
| 165 |
+
# Generate VIPS classification
|
| 166 |
+
response = mistral_client.generate(
|
| 167 |
+
prompt=prompt,
|
| 168 |
+
max_tokens=max_tokens,
|
| 169 |
+
temperature=Config.LLM_TEMPERATURE
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
# Apply GDPR Layer 2: Anonymize output
|
| 173 |
+
_, anonymized_output = apply_dual_layer_gdpr("", response)
|
| 174 |
+
|
| 175 |
+
# Parse VIPS categories from response
|
| 176 |
+
vips = parse_vips_response(anonymized_output)
|
| 177 |
+
|
| 178 |
+
return vips
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def parse_vips_response(response: str) -> dict:
|
| 182 |
+
"""
|
| 183 |
+
Parse VIPS categories from LLM response
|
| 184 |
+
|
| 185 |
+
Args:
|
| 186 |
+
response: Raw LLM response
|
| 187 |
+
|
| 188 |
+
Returns:
|
| 189 |
+
Dictionary with parsed VIPS categories
|
| 190 |
+
"""
|
| 191 |
+
vips = {
|
| 192 |
+
"V": "Ingen relevant information.",
|
| 193 |
+
"I": "Ingen relevant information.",
|
| 194 |
+
"P": "Ingen relevant information.",
|
| 195 |
+
"S": "Ingen relevant information."
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
lines = response.strip().split('\n')
|
| 199 |
+
|
| 200 |
+
for line in lines:
|
| 201 |
+
line = line.strip()
|
| 202 |
+
if line.startswith("V:"):
|
| 203 |
+
vips["V"] = line[2:].strip()
|
| 204 |
+
elif line.startswith("I:"):
|
| 205 |
+
vips["I"] = line[2:].strip()
|
| 206 |
+
elif line.startswith("P:"):
|
| 207 |
+
vips["P"] = line[2:].strip()
|
| 208 |
+
elif line.startswith("S:"):
|
| 209 |
+
vips["S"] = line[2:].strip()
|
| 210 |
+
|
| 211 |
+
return vips
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|