Downloads · 30 days
703
5% of all-time downloads
alpha-ai/Medical-Diagnosis-COT-Gemma3-270M
Medical-Diagnosis-COT-Gemma3-270M is a text generation model from alpha-ai. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
<div align="center" <img src="https://huggingface.co/alpha-ai/Medical-Diagnosis-COT-Gemma3-270M/resolve/main/Medical-Diagnosis-COT-Gemma3-270M.png" alt="Model card" style="width: 500px; height: auto; object-position:…
Downloads · 30 days
703
5% of all-time downloads
All-time downloads
12.9K
Public
Parameters
268M
1.4 GB on disk
Likes
16
Public
Click a slice to open those files.
.gguf834 MB · 59%
How the weights are stored.
BF16168M · 63%
From the Hugging Face model README
Alpha AI (www.alphaai.biz) fine-tuned Gemma-3 270M for medical question answering with explicit chain-of-thought (CoT). The model emits reasoning inside <think> ... </think> followed by a final answer, making it well-suited for research on verifiable medical reasoning and for internal tooling where transparent intermediate steps are desired.
⚠️Not for clinical use. This model is a research system, not a medical device. Do not use it for diagnosis or treatment decisions.
google/gemma-3-270m-it (Gemma 3, 270M params). Access requires accepting Google’s Gemma license on Hugging Face.FreedomIntelligence/medical-o1-reasoning-SFT (en split; columns: Question, Complex_CoT, Response).<think>…</think> (reasoning) + final answer.Intended use
Out of scope / limitations
Dataset license is Apache-2.0; the base model is covered by Google's Gemma license, review these before use.
Source: FreedomIntelligence/medical-o1-reasoning-SFT + Human annotated and filtered medical diagnosis data
en): ~19.7k rows with fields Question, Complex_CoT, Response. Total dataset ≈ 90,120 rows across splits/languages.Preprocessing
<think>{Complex_CoT}</think>\n{Response}.Training prompt style (system + user + assistant):
System:
Below is an instruction that describes a task,
paired with an input that provides further context.
Write a response that appropriately completes the request.
Before answering, think carefully about the question and create a step-by-step
chain of thoughts to ensure a logical and accurate response.
### Instruction:
You are a medical expert with advanced knowledge in clinical reasoning,
diagnostics, and treatment planning.
Please answer the following medical question.
User:
### Question:
{question}
### Response:
Assistant:
<think>
{complex_cot}
</think>
{final_answer}
Generation tip (serve-time):
If you don’t want to expose CoT to end-users, post-process generated text to strip the <think> ... </think> block and only show the final answer.
Python snippet to strip CoT:
import re
def strip_think(text: str) -> str:
return re.sub(r"<think>.*?</think>\s*", "", text, flags=re.S|re.I).strip()
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "alphaaico/Medical-Diagnosis-COT-Gemma3-270M"
tok = AutoTokenizer.from_pretrained(repo)
mdl = AutoModelForCausalLM.from_pretrained(repo, device_map="auto")
prompt = """### Question:
A 65-year-old with exertional dyspnea and orthopnea presents with bilateral
pitting edema and raised JVP. What initial pharmacologic therapy is indicated?
### Response:
"""
from transformers import TextStreamer
streamer = TextStreamer(tok, skip_prompt=True, skip_special_tokens=True)
inputs = tok.apply_chat_template(
[{"role":"system","content":"You are a careful medical reasoner."},
{"role":"user","content":prompt}],
tokenize=True, add_generation_prompt=True, return_tensors="pt"
).to(mdl.device)
out = mdl.generate(**inputs, max_new_tokens=256, temperature=1.0, top_p=0.95, top_k=64, streamer=streamer)
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
base = "google/gemma-3-270m-it" # requires accepting Gemma license on Hugging Face
repo = "alphaaico/Medical-Diagnosis-COT-Gemma3-270M"
tok = AutoTokenizer.from_pretrained(base)
base_mdl = AutoModelForCausalLM.from_pretrained(base, device_map="auto")
mdl = PeftModel.from_pretrained(base_mdl, repo) # merges LoRA at runtime
mdl.eval()
If you see a 403/404 on the base model, make sure you’ve accepted Google’s Gemma license in your Hugging Face account.
SFTTrainer (supervised finetuning).Key hyperparameters (demo run that produced loss ≈ 3.3):
max_steps=500 , ideall go beyond 1500 for better results.adamw_8bit, weight_decay=0.01, lr_scheduler_type=linear5e-5 (for longer runs, 2e-5 is often more stable)per_device_train_batch_size=8, gradient_accumulation_steps=1warmup_steps=53407Note: For very long CoT sequences on small GPUs (e.g., T4 16 GB), consider
per_device_train_batch_size=1+ gradient accumulation and a largermax_seq_length. Gemma 3 supports up to 128K context, but practical fine-tuning length depends on memory. For smaller queries, everything fits well for this to be used on edge devices.
<think>…</think> followed by an answer.FreedomIntelligence/medical-o1-reasoning-SFT — Apache-2.0.Please cite the dataset if you use this model:
@misc{chen2024huatuogpto1medicalcomplexreasoning,
title={HuatuoGPT-o1, Towards Medical Complex Reasoning with LLMs},
author={Junying Chen and Zhenyang Cai and Ke Ji and Xidong Wang and Wanlong Liu and Rongsheng Wang and Jianye Hou and Benyou Wang},
year={2024},
eprint={2412.18925},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2412.18925}
}
medical-o1-reasoning-SFT.Questions, issues, or contributions: open a Discussion on this repo. For enterprise collaboration with Alpha AI, reach out via the organization profile on Hugging Face or find us on www.alphaai.biz.
from transformers import AutoModelForCausalLM, AutoTokenizer
import re
repo = "alphaaico/Medical-Diagnosis-COT-Gemma3-270M"
tok = AutoTokenizer.from_pretrained(repo)
mdl = AutoModelForCausalLM.from_pretrained(repo, device_map="auto")
def strip_think(txt): return re.sub(r"<think>.*?</think>\s*", "", txt, flags=re.S|re.I).strip()
def ask(question):
user = f"### Question:\n\n{question}\n\n### Response:"
msgs = [
{"role":"system","content":"You are a medical expert. Think step-by-step, then answer succinctly."},
{"role":"user","content":user},
]
prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
out = mdl.generate(**tok(prompt, return_tensors="pt").to(mdl.device), max_new_tokens=512, temperature=1.0, top_p=0.95, top_k=64)
text = tok.decode(out[0], skip_special_tokens=True)
return strip_think(text)
print(ask("Elderly patient with new ankle swelling on thiazolidinedione—likely cause?"))