input_dim = 768# e.g., the hidden size of the pre-trained model output_dim = 768# e.g., the output size of the layer rank = 8# The rank 'r' for the low-rank adaptation
W = ... # from pretrained network with shape input_dim x output_dim
W_A = nn.Parameter(torch.empty(input_dim, rank)) # LoRA weight A W_B = nn.Parameter(torch.empty(rank, output_dim)) # LoRA weight B
# Initialization of LoRA weights nn.init.kaiming_uniform_(W_A, a=math.sqrt(5)) nn.init.zeros_(W_B)
defregular_forward_matmul(x, W): h = x @ W return h
deflora_forward_matmul(x, W, W_A, W_B): h = x @ W # regular matrix multiplication h += x @ (W_A @ W_B)*alpha # use scaled LoRA weights return h
text = f"""### Instruction: 你是一名医学专家,请根据病例信息选择最合理的答案。 ### Question: {example['sent1']}{example['sent2']} ### Options: A. {options[0]} B. {options[1]} C. {options[2]} D. {options[3]} E. {options[4]} ### Answer: {labels[correct_idx]}. {options[correct_idx]} """ return {"text": text}
id ending0 \ 0 2622 Pallor, cyanosis, and erythema of the hands 1 1754 CGG 2 3718 Release of vascular endothelial growth factor 3 9107 Left-sided heart failure 4 1838 Increase oral hydration and fiber intake
ending1 \ 0 Calcium deposits on digits 1 GAA 2 Cellular retention of sodium 3 Coronary artery disease 4 Check the stool for fecal red blood cells and ...
ending3 ending4 \ 0 Hypercoagulable state Heartburn and regurgitation 1 CTG GCC 2 Degranulation of eosinophils Increased hydrostatic pressure 3 Budd-chiari syndrome Cor pulmonale 4 Begin treatment with ciprofloxacin Begin cognitive behavioral therapy
label sent1 \ 0 3 A 35-year-old woman comes to your office with ... 1 1 An 8-year-old boy is brought to the pediatrici... 2 2 A 36-year-old man is brought to the emergency ... 3 4 A 35-year-old woman presents to the ER with sh... 4 4 A 5-year-old boy is brought in by his parents ...
sent2 \ 0 All of the following symptoms and signs would ... 1 Which of the following trinucleotide repeats i... 2 Which of the following is most likely the prim... 3 What is the most likely diagnosis? 4 After a conversation with the child exploring ...
startphrase 0 A 35-year-old woman comes to your office with ... 1 An 8-year-old boy is brought to the pediatrici... 2 A 36-year-old man is brought to the emergency ... 3 A 35-year-old woman presents to the ER with sh... 4 A 5-year-old boy is brought in by his parents ...