Views
No views yet
| Model | Department (F1) | Severity (F1) |
|---|---|---|
| ThaiLLM-27B (Zero-shot) | 0.2320 | 0.2215 |
| ThaiLLM-27B-Prescreen | 0.3919 | 0.2186 |
| Medgemma-27B-it (Zero-shot) | 0.3853 | 0.3031 |
| Hyperparemeter | Value |
|---|---|
| Learning Rate | 2e-4 |
| LoRA Rank | 16 |
| LoRA Alpha | 32 |
| Sequence Length | 2048 |
| Epochs | 3 |
| Batch size | 32 |
1git clone https://github.com/axolotl-ai-cloud/axolotl.git
2
3pip3 install -U packaging setuptools wheel ninja
4pip3 install --no-build-isolation axolotl[flash-attn,deepspeed]
5
6axolotl train prescreen.yaml1base_model: ThaiLLM/ThaiLLM-27B
2plugins:
3 - axolotl.integrations.cut_cross_entropy.CutCrossEntropyPlugin
4strict: false
5
6chat_template: gemma3
7datasets:
8 - path: prescreen.jsonl
9 type: alpaca
10output_dir: ./outputs/ThaiLLM-27B-Prescreen
11
12sequence_len: 2048
13sample_packing: true
14ddp_find_unused_parameters: true
15
16load_in_4bit: true
17adapter: qlora
18lora_r: 16
19lora_alpha: 32
20lora_target_modules:
21 - q_proj
22 - k_proj
23 - v_proj
24 - o_proj
25 - down_proj
26 - up_proj
27lora_mlp_kernel: true
28lora_qkv_kernel: true
29lora_o_kernel: true
30
31gradient_accumulation_steps: 8
32micro_batch_size: 1
33num_epochs: 3
34optimizer: adamw_torch_4bit
35lr_scheduler: cosine
36learning_rate: 2e-4
37
38bf16: auto
39tf32: true
40
41logging_steps: 1
42flash_attention: true
43warmup_ratio: 0.1
44saves_per_epoch: 3
45weight_decay: 0.011system_prompt = """# Instruction
2You will receive a conversation between a doctor and a patient. The doctor asks diagnostic questions, and the patient provides responses about their symptoms, history, and condition.
3
4## Your Task
5Analyze the conversation and classify the case into three categories:
61. **Disease/Condition**: The specific medical condition the patient is suffering from
72. **Department**: The appropriate medical department for treatment
83. **Severity**: The urgency level of the case
9
10## Classification Guidelines
11### Disease/Condition
12- Base your diagnosis on the symptom pattern, onset, duration, and clinical features
13- Consider the most likely diagnosis given the presenting symptoms
14### Department Selection
15- Choose from: Dermatology, Emergency Medicine, Internal Medicine, Obstetrics-Gynecology, Ophthalmology, Orthopedics and Physical Therapy, Otolaryngology, Pediatrics, Psychiatry, Self-care / Observation, Surgery
16### Severity Levels
17- **Emergency**: Life-threatening conditions requiring immediate medical attention (severe pain >7/10, sudden onset of serious symptoms, signs of organ failure, severe bleeding, difficulty breathing, loss of consciousness)
18- **Visit Hospital / Clinic**: Conditions requiring professional medical evaluation but not immediately life-threatening (moderate symptoms, persistent issues, need for diagnosis/treatment)
19- **Observe at Home**: Minor conditions manageable with self-care and monitoring (mild symptoms, known conditions with clear management)
20
21## Output Format
22# Respond with ONLY a valid JSON object in this exact format:
23# {\"disease\": \"exact disease name\", \"department\": \"exact department name\", \"severity\": \"Emergency|Visit Hospital / Clinic|Observe at Home\"}"""
24
25prompt = """## Conversation
26Doctor: เริ่มมีท้องเสียตั้งแต่เมื่อไร?
27Patient: เริ่มมีอาการท้องเสียประมาณ 2 เดือนที่แล้วค่ะ
28Doctor: มีอาการมานานเท่าไร?
29Patient: ท้องเสียมาประมาณ 2 เดือนแล้วค่ะ
30Doctor: ลักษณะอุจจาระเป็นอย่างไร ถ่ายเป็นน้ำ เนื้อปนน้ำ มีมูกเลือด หรือเลือดสด?"""1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4messages = [
5 {"role": "system", "content": system_prompt},
6 {"role": "user", "content": prompt}
7]
8
9tokenizer = AutoTokenizer.from_pretrained("ThaiLLM/ThaiLLM-27B-Prescreen", use_fast=True)
10chat = tokenizer.apply_chat_template(prompt, add_generation_prompt=True, return_tensors="pt")
11model = AutoModelForCausalLM.from_pretrained("ThaiLLM/ThaiLLM-27B-Prescreen", device_map="auto", dtype=torch.bfloat16)
12
13output = model.generate(chat.input_ids, max_new_tokens=256)
14response = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
15print(response)