Views
No views yet
Qwen/Qwen2.5-1.5B architecture and has undergone a rigorous dual-stage training pipeline to eliminate hallucinations and maximize clinical accuracy while remaining deployable on low-VRAM edge hardware.bfloat16 precision on consumer or serverless GPU instances (e.g., RunPod, vLLM).gamino/wiki_medical_termsmedalpaca/medical_meadow_medical_flashcardstransformers library. Ensure your inference script uses low temperatures for maximum medical accuracy.pip install torch transformers acceleration safetensors1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "Mix80/ClinicaQwen-MedQA"
5
6print("Loading ClinicaQwen-MedQA...")
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 torch_dtype=torch.bfloat16,
11 device_map="auto"
12)
13
14def ask_clinica_qwen(question, max_new_tokens=150):
15 # Construct the strict conversational template
16 prompt = f"User: {question}\nBot:"
17
18 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
19
20 outputs = model.generate(
21 **inputs,
22 max_new_tokens=max_new_tokens,
23 temperature=0.1, # Crucial: Low temp ensures strict factual adherence
24 top_p=0.85,
25 do_sample=True,
26 repetition_penalty=1.3, # Prevents linguistic loops
27 no_repeat_ngram_size=3,
28 pad_token_id=tokenizer.eos_token_id
29 )
30
31 # Extract only the generated answer tokens, skipping the prompt prefix
32 prompt_length = inputs.input_ids.shape[1]
33 generated_tokens = outputs[0][prompt_length:]
34
35 answer = tokenizer.decode(generated_tokens, skip_special_tokens=True).strip()
36 return answer
37
38# Test the model
39sample_query = "What are the key differences between a tension headache and a migraine?"
40response = ask_clinica_qwen(sample_query)
41
42print(f"\nQuestion: {sample_query}")
43print(f"ClinicaQwen: {response}")