medalpaca/medalpaca-7b base model. Unlike its SFT predecessor, this model leverages the superior knowledge and reasoning capabilities of the larger google/medgemma-27b-it model as a "teacher" to guide the training of the smaller, more efficient "student" model. This results in a compact model that captures the clinical acumen of a much larger counterpart.| Stage | Purpose | Methodology & Quality Control |
|---|---|---|
| A. Augmented Query Generation | Create a diverse set of high-quality input prompts. | Utilizes the same multi-model paraphrasing, back-translation, and style standardization pipeline from the SFT model to generate a rich variety of instructions and inputs. |
| B. Teacher Forcing & Output Generation | Generate "gold-standard" responses using the superior teacher model. | Teacher Model: google/medgemma-27b-it. Generation Strategy: Low-temperature sampling with contrastive decoding to produce confident, factually-dense, and well-structured answers. Input: The entire augmented set of (Instruction, Input) pairs from Stage A. |
| C. Response Filtering & Alignment | Ensure the teacher's outputs are of the highest quality for student training. | Factual Consistency Check: Cross-referencing key medical claims against the original context. Style Alignment: Enforcing the neutral, professional clinical tone. Complexity Pruning: Removing outputs that are overly verbose or rely on reasoning chains too complex for the student model to learn effectively. |
| D. Dual-Phase Knowledge Distillation | Transfer knowledge from teacher to student. | Phase 1 (Response Mimicking): The student model is trained to directly reproduce the teacher's filtered outputs, learning its style and factual presentation. Phase 2 (Logit Matching): The student is trained to align its internal probability distributions (logits) with the teacher's for the same input, capturing the teacher's "thinking process" and confidence calibration. |
| E. Quality Assurance | Ensure the final training pairs are optimal for distillation. | F1. Data Cleaning: PHI removal; MD5-based deduplication. F2. KD-Specific Validation: Checking for alignment between query complexity and response depth; ensuring student-trainable reasoning patterns. |
### Instruction:
{Task descriptor and/or user question with context}
### Input:
{Additional user question or context, if any}
### Output:
{The teacher model's (MedGemma-27b) target response}distilled_from: medgemma-27b tag.transformers library, identical to the SFT version but with potentially improved performance.1import transformers
2
3model_id = "MedAI-COS30018/MedSwin-7B-KD"
4pipeline = transformers.pipeline(
5 "text-generation",
6 model=model_id,
7 device_map="auto", # Use GPU if available
8)
9
10# Format your input according to the training template
11instruction = "Based on the provided context, what is the most likely diagnosis?"
12context = "A 45-year-old male presents with acute, crushing substernal chest pain radiating to the left arm, associated with diaphoresis and nausea for the past hour."
13formatted_prompt = f"### Instruction:\n{instruction}\n\n### Input:\n{context}\n\n### Output:\n"
14
15# Generate a response
16sequences = pipeline(
17 formatted_prompt,
18 max_new_tokens=256,
19 do_sample=True,
20 temperature=0.3,
21 top_p=0.9,
22 eos_token_id=pipeline.tokenizer.eos_token_id,
23)
24print(sequences[0]['generated_text'])Review all model metrics benchmark via Benchmark Document Preview.