CoolFace
Modelpublic

Abc7347/clone

sourceHugging Faceotherupdated 8mo agoView on Hugging Face
0likes12downloads
README.md528 linesDownload Raw Back to root
1---2license: other3license_name: health-ai-developer-foundations4license_link: https://developers.google.com/health-ai-developer-foundations/terms5library_name: transformers6pipeline_tag: image-text-to-text7extra_gated_heading: Access MedGemma on Hugging Face8extra_gated_prompt: >-9  To access MedGemma on Hugging Face, you're required to review and agree to10  [Health AI Developer Foundation's terms of11  use](https://developers.google.com/health-ai-developer-foundations/terms). To12  do this, please ensure you're logged in to Hugging Face and click below.13  Requests are processed immediately.14extra_gated_button_content: Acknowledge license15base_model:16- google/medgemma-27b-text-it17tags:18- medical19- unsloth20  - clinical-reasoning21  - thinking22---23<div>24<p style="margin-top: 0;margin-bottom: 0;">25    <em><a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0</a> achieves superior accuracy & outperforms other leading quants.</em>26  </p>27  <div style="display: flex; gap: 5px; align-items: center; ">28    <a href="https://github.com/unslothai/unsloth/">29      <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">30    </a>31    <a href="https://discord.gg/unsloth">32      <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">33    </a>34    <a href="https://docs.unsloth.ai/basics/qwen3-how-to-run-and-fine-tune">35      <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">36    </a>37  </div>38</div>39 40 41# MedGemma model card42 43**Model documentation:** [MedGemma](https://developers.google.com/health-ai-developer-foundations/medgemma)44 45**Resources:**46 47*   Model on Google Cloud Model Garden: [MedGemma](https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/medgemma)48*   Model on Hugging Face: [MedGemma](https://huggingface.co/collections/google/medgemma-release-680aade845f90bec6a3f60c4)49*   GitHub repository (supporting code, Colab notebooks, discussions, and50    issues): [MedGemma](https://github.com/google-health/medgemma)51*   Quick start notebook: [GitHub](https://github.com/google-health/medgemma/blob/main/notebooks/quick_start_with_hugging_face.ipynb)52*   Fine-tuning notebook: [GitHub](https://github.com/google-health/medgemma/blob/main/notebooks/fine_tune_with_hugging_face.ipynb)53*   [Patient Education Demo built using MedGemma](https://huggingface.co/spaces/google/rad_explain)54*   Support: See [Contact](https://developers.google.com/health-ai-developer-foundations/medgemma/get-started.md#contact)55*   License: The use of MedGemma is governed by the [Health AI Developer56    Foundations terms of57    use](https://developers.google.com/health-ai-developer-foundations/terms).58 59**Author:** Google60 61## Model information62 63This section describes the MedGemma model and how to use it.64 65### Description66 67MedGemma is a collection of [Gemma 3](https://ai.google.dev/gemma/docs/core)68variants that are trained for performance on medical text and image69comprehension. Developers can use MedGemma to accelerate building70healthcare-based AI applications. MedGemma currently comes in two variants: a 4B71multimodal version and a 27B text-only version.72 73MedGemma 27B has been trained exclusively on medical text and optimized for74inference-time computation. MedGemma 27B is only available as an75instruction-tuned model.76 77MedGemma variants have been evaluated on a range of clinically relevant78benchmarks to illustrate their baseline performance. These include both open79benchmark datasets and curated datasets. Developers can fine-tune MedGemma80variants for improved performance. Consult the Intended Use section below for81more details.82 83A full technical report will be available soon.84 85### How to use86 87Below are some example code snippets to help you quickly get started running the88model locally on GPU. If you want to use the model at scale, we recommend that89you create a production version using [Model90Garden](https://cloud.google.com/model-garden).91 92First, install the Transformers library. Gemma 3 is supported starting from93transformers 4.50.0.94 95```sh96$ pip install -U transformers97```98 99**Run model with the `pipeline` API**100 101```python102from transformers import pipeline103import torch104 105pipe = pipeline(106    "text-generation",107    model="google/medgemma-27b-text-it",108    torch_dtype=torch.bfloat16,109    device="cuda",110)111 112messages = [113    {114        "role": "system",115        "content": "You are a helpful medical assistant."116    },117    {118        "role": "user",119        "content": "How do you differentiate bacterial from viral pneumonia?"120    }121]122 123output = pipe(text=messages, max_new_tokens=200)124print(output[0]["generated_text"][-1]["content"])125```126 127**Run the model directly**128 129```python130# pip install accelerate131from transformers import AutoTokenizer, AutoModelForCausalLM132import torch133 134model_id = "google/medgemma-27b-text-it"135 136model = AutoModelForCausalLM.from_pretrained(137    model_id,138    torch_dtype=torch.bfloat16,139    device_map="auto",140)141tokenizer = AutoTokenizer.from_pretrained(model_id)142 143messages = [144    {145        "role": "system",146        "content": "You are a helpful medical assistant."147    },148    {149        "role": "user",150        "content": "How do you differentiate bacterial from viral pneumonia?"151    }152]153 154inputs = tokenizer.apply_chat_template(155    messages,156    add_generation_prompt=True,157    tokenize=True,158    return_dict=True,159    return_tensors="pt",160).to(model.device)161 162input_len = inputs["input_ids"].shape[-1]163 164with torch.inference_mode():165    generation = model.generate(**inputs, max_new_tokens=200, do_sample=False)166    generation = generation[0][input_len:]167 168decoded = tokenizer.decode(generation, skip_special_tokens=True)169print(decoded)170```171 172### Examples173 174See the following Colab notebooks for examples of how to use MedGemma:175 176*   To give the model a quick try, running it locally with weights from Hugging177    Face, see [Quick start notebook in178    Colab](https://colab.research.google.com/github/google-health/medgemma/blob/main/notebooks/quick_start_with_hugging_face.ipynb). Note that you will need to use Colab179    Enterprise to run the 27B model without quantization.180 181*   For an example of fine-tuning the model, see the [Fine-tuning notebook in182    Colab](https://colab.research.google.com/github/google-health/medgemma/blob/main/notebooks/fine_tune_with_hugging_face.ipynb).183 184### Model architecture overview185 186The MedGemma model is built based on [Gemma 3](https://ai.google.dev/gemma/) and187uses the same decoder-only transformer architecture as Gemma 3. To read more188about the architecture, consult the Gemma 3 [model189card](https://ai.google.dev/gemma/docs/core/model_card_3).190 191### Technical specifications192 193*   **Model type**: Decoder-only Transformer architecture, see the [Gemma 3194    technical195    report](https://storage.googleapis.com/deepmind-media/gemma/Gemma3Report.pdf)196*   **Modalities**: **4B**: Text, vision; **27B**: Text only197*   **Attention mechanism**: Utilizes grouped-query attention (GQA)198*   **Context length**: Supports long context, at least 128K tokens199*   **Key publication**: Coming soon200*   **Model created**: May 20, 2025201*   **Model version**: 1.0.0202 203### Citation204 205A technical report is coming soon. In the meantime, if you publish using this206model, please cite the Hugging Face model page:207 208```none209@misc{medgemma-hf,210    author = {Google},211    title = {MedGemma Hugging Face}212    howpublished = {\url{https://huggingface.co/collections/google/medgemma-release-680aade845f90bec6a3f60c4}},213    year = {2025},214    note = {Accessed: [Insert Date Accessed, e.g., 2025-05-20]}215}216```217 218### Inputs and outputs219 220**Input**:221 222*   Text string, such as a question or prompt223*   Total input length of 128K tokens224 225**Output**:226 227*   Generated text in response to the input, such as an answer to a question,228    analysis of image content, or a summary of a document229*   Total output length of 8192 tokens230 231### Performance and validation232 233MedGemma was evaluated across a range of different multimodal classification,234report generation, visual question answering, and text-based tasks.235 236### Key performance metrics237 238#### Text evaluations239 240MedGemma 4B and text-only MedGemma 27B were evaluated across a range of241text-only benchmarks for medical knowledge and reasoning.242 243The MedGemma models outperform their respective base Gemma models across all244tested text-only health benchmarks.245 246| Metric | MedGemma 27B | Gemma 3 27B | MedGemma 4B | Gemma 3 4B |247| :---- | :---- | :---- | :---- | :---- |248| MedQA (4-op) | 89.8 (best-of-5) 87.7 (0-shot) | 74.9 | 64.4 | 50.7 |249| MedMCQA | 74.2 | 62.6 | 55.7 | 45.4 |250| PubMedQA | 76.8 | 73.4 | 73.4 | 68.4 |251| MMLU Med (text only) | 87.0 | 83.3 | 70.0 | 67.2 |252| MedXpertQA (text only) | 26.7 | 15.7 | 14.2 | 11.6 |253| AfriMed-QA | 84.0 | 72.0 | 52.0 | 48.0 |254 255For all MedGemma 27B results, [test-time256scaling](https://arxiv.org/abs/2501.19393) is used to improve performance.257 258### Ethics and safety evaluation259 260#### Evaluation approach261 262Our evaluation methods include structured evaluations and internal red-teaming263testing of relevant content policies. Red-teaming was conducted by a number of264different teams, each with different goals and human evaluation metrics. These265models were evaluated against a number of different categories relevant to266ethics and safety, including:267 268*   **Child safety**: Evaluation of text-to-text and image-to-text prompts269    covering child safety policies, including child sexual abuse and270    exploitation.271*   **Content safety:** Evaluation of text-to-text and image-to-text prompts272    covering safety policies, including harassment, violence and gore, and hate273    speech.274*   **Representational harms**: Evaluation of text-to-text and image-to-text275    prompts covering safety policies, including bias, stereotyping, and harmful276    associations or inaccuracies.277*   **General medical harms:** Evaluation of text-to-text and image-to-text278    prompts covering safety policies, including information quality and harmful279    associations or inaccuracies.280 281In addition to development level evaluations, we conduct "assurance evaluations"282which are our "arms-length" internal evaluations for responsibility governance283decision making. They are conducted separately from the model development team,284to inform decision making about release. High-level findings are fed back to the285model team, but prompt sets are held out to prevent overfitting and preserve the286results' ability to inform decision making. Notable assurance evaluation results287are reported to our Responsibility & Safety Council as part of release review.288 289#### Evaluation results290 291For all areas of safety testing, we saw safe levels of performance across the292categories of child safety, content safety, and representational harms. All293testing was conducted without safety filters to evaluate the model capabilities294and behaviors. For text-to-text, image-to-text, and audio-to-text, and across295both MedGemma model sizes, the model produced minimal policy violations. A296limitation of our evaluations was that they included primarily English language297prompts.298 299## Data card300 301### Dataset overview302 303#### Training304 305The base Gemma models are pre-trained on a large corpus of text and code data.306MedGemma 4B utilizes a [SigLIP](https://arxiv.org/abs/2303.15343) image encoder307that has been specifically pre-trained on a variety of de-identified medical308data, including radiology images, histopathology images, ophthalmology images,309and dermatology images. Its LLM component is trained on a diverse set of medical310data, including medical text relevant to radiology images, chest-x rays,311histopathology patches, ophthalmology images and dermatology images.312 313#### Evaluation314 315MedGemma models have been evaluated on a comprehensive set of clinically316relevant benchmarks, including over 22 datasets across 5 different tasks and 6317medical image modalities. These include both open benchmark datasets and curated318datasets, with a focus on expert human evaluations for tasks like CXR report319generation and radiology VQA.320 321#### Source322 323MedGemma utilizes a combination of public and private datasets.324 325This model was trained on diverse public datasets including MIMIC-CXR (chest326X-rays and reports), Slake-VQA (multimodal medical images and questions),327PAD-UFES-20 (skin lesion images and data), SCIN (dermatology images), TCGA328(cancer genomics data), CAMELYON (lymph node histopathology images), PMC-OA329(biomedical literature with images), and Mendeley Digital Knee X-Ray (knee330X-rays).331 332Additionally, multiple diverse proprietary datasets were licensed and333incorporated (described next).334 335### Data Ownership and Documentation336 337*   [Mimic-CXR](https://physionet.org/content/mimic-cxr/2.1.0/): MIT Laboratory338    for Computational Physiology and Beth Israel Deaconess Medical Center339    (BIDMC).340*   [Slake-VQA](https://www.med-vqa.com/slake/): The Hong Kong Polytechnic341    University (PolyU), with collaborators including West China Hospital of342    Sichuan University and Sichuan Academy of Medical Sciences / Sichuan343    Provincial People's Hospital.344*   [PAD-UFES-20](https://pmc.ncbi.nlm.nih.gov/articles/PMC7479321/): Federal345    University of Espírito Santo (UFES), Brazil, through its Dermatological and346    Surgical Assistance Program (PAD).347*   [SCIN](https://github.com/google-research-datasets/scin): A collaboration348    between Google Health and Stanford Medicine.349*   [TCGA](https://portal.gdc.cancer.gov/) (The Cancer Genome Atlas): A joint350    effort of National Cancer Institute and National Human Genome Research351    Institute. Data from TCGA are available via the Genomic Data Commons (GDC)352*   [CAMELYON](https://camelyon17.grand-challenge.org/Data/): The data was353    collected from Radboud University Medical Center and University Medical354    Center Utrecht in the Netherlands.355*   [PMC-OA (PubMed Central Open Access356    Subset)](https://catalog.data.gov/dataset/pubmed-central-open-access-subset-pmc-oa):357    Maintained by the National Library of Medicine (NLM) and National Center for358    Biotechnology Information (NCBI), which are part of the NIH.359*   [MedQA](https://arxiv.org/pdf/2009.13081): This dataset was created by a360    team of researchers led by Di Jin, Eileen Pan, Nassim Oufattole, Wei-Hung361    Weng, Hanyi Fang, and Peter Szolovits362*   [Mendeley Digital Knee363    X-Ray](https://data.mendeley.com/datasets/t9ndx37v5h/1): This dataset is364    from Rani Channamma University, and is hosted on Mendeley Data.365*   [AfriMed-QA](https://afrimedqa.com/): This data was developed and led by366    multiple collaborating organizations and researchers include key367    contributors: Intron Health, SisonkeBiotik, BioRAMP, Georgia Institute of368    Technology, and MasakhaneNLP.369*   [VQA-RAD](https://www.nature.com/articles/sdata2018251): This dataset was370    created by a research team led by Jason J. Lau, Soumya Gayen, Asma Ben371    Abacha, and Dina Demner-Fushman and their affiliated institutions (the US372    National Library of Medicine and National Institutes of Health)373*   [MedExpQA](https://www.sciencedirect.com/science/article/pii/S0933365724001805):374    This dataset was created by researchers at the HiTZ Center (Basque Center375    for Language Technology and Artificial Intelligence).376*   [MedXpertQA](https://huggingface.co/datasets/TsinghuaC3I/MedXpertQA): This377    dataset was developed by researchers at Tsinghua University (Beijing, China)378    and Shanghai Artificial Intelligence Laboratory (Shanghai, China).379 380In addition to the public datasets listed above, MedGemma was also trained on381de-identified datasets licensed for research or collected internally at Google382from consented participants.383 384*   Radiology dataset 1: De-identified dataset of different CT studies across385    body parts from a US-based radiology outpatient diagnostic center network.386*   Ophthalmology dataset 1: De-identified dataset of fundus images from387    diabetic retinopathy screening.388*   Dermatology dataset 1: De-identified dataset of teledermatology skin389    condition images (both clinical and dermatoscopic) from Colombia.390*   Dermatology dataset 2: De-identified dataset of skin cancer images (both391    clinical and dermatoscopic) from Australia.392*   Dermatology dataset 3: De-identified dataset of non-diseased skin images393    from an internal data collection effort.394*   Pathology dataset 1: De-identified dataset of histopathology H&E whole slide395    images created in collaboration with an academic research hospital and396    biobank in Europe. Comprises de-identified colon, prostate, and lymph nodes.397*   Pathology dataset 2: De-identified dataset of lung histopathology H&E and398    IHC whole slide images created by a commercial biobank in the United States.399*   Pathology dataset 3: De-identified dataset of prostate and lymph node H&E400    and IHC histopathology whole slide images created by a contract research401    organization in the United States.402*   Pathology dataset 4: De-identified dataset of histopathology, predominantly403    H\&E whole slide images created in collaboration with a large, tertiary404    teaching hospital in the United States. Comprises a diverse set of tissue405    and stain types, predominantly H&E.406 407### Data citation408 409*   MIMIC-CXR Johnson, A., Pollard, T., Mark, R., Berkowitz, S., & Horng, S.410    (2024). MIMIC-CXR Database (version 2.1.0). PhysioNet.411*   Johnson, A.E.W., Pollard, T.J., Berkowitz, S.J. et al. [MIMIC-CXR, a412    de-identified publicly available database of chest radiographs with413    free-text reports. Sci Data 6, 317414    (2019).](https://doi.org/10.1038/s41597-019-0322-0)415*   Available on Physionet Goldberger, A., Amaral, L., Glass, L., Hausdorff, J.,416    Ivanov, P. C., Mark, R., ... & Stanley, H. E. (2000). [PhysioBank,417    PhysioToolkit, and PhysioNet: Components of a new research resource for418    complex physiologic signals. Circulation \[Online\]. 101 (23), pp.419    E215–e220.](https://pubmed.ncbi.nlm.nih.gov/10851218/)420*   Bo Liu, Li-Ming Zhan, etc. [SLAKE: A Semantically-Labeled Knowledge-Enhanced421    Dataset for Medical Visual Question422    Answering](https://arxiv.org/abs/2102.09542).423*   [PAD-UFES-20: A skin lesion dataset composed of patient data and clinical424    images collected from425    smartphones](https://pmc.ncbi.nlm.nih.gov/articles/PMC7479321/)426*   [The Cancer Genome Atlas Program (TCGA)](https://www.cancer.gov/ccg/research/genome-sequencing/tcga)427*   Babak Ehteshami Bejnordi, etc.: [Diagnostic Assessment of Deep Learning428    Algorithms for Detection of Lymph Node Metastases in Women With Breast429    Cancer](https://jamanetwork.com/journals/jama/fullarticle/2665774)430*   MedQA: [https://arxiv.org/abs/2009.13081](https://arxiv.org/abs/2009.13081)431*   Mendeley Digital Knee X-Ray: Gornale, Shivanand; Patravali, Pooja (2020),432    "Digital Knee X-ray Images", Mendeley Data, V1, doi: 10.17632/t9ndx37v5h.1433*   AfriMed-QA: [https://arxiv.org/abs/2411.15640](https://arxiv.org/abs/2411.15640)434*   VQA-RAD: [Lau, J., Gayen, S., Ben Abacha, A. et al. A dataset of clinically435    generated visual questions and answers about radiology images. Sci Data 5,436    180251 (2018).437    https://doi.org/10.1038/sdata.2018.251](https://doi.org/10.1038/sdata.2018.251)438*   [MedExpQA: Multilingual benchmarking of Large Language Models for439    Medical Question440    Answering](https://www.sciencedirect.com/science/article/pii/S0933365724001805)441*   MedXpertQA: [arXiv:2501.18362v2](https://arxiv.org/abs/2501.18362)442 443### De-identification/anonymization:444 445Google and partnerships utilize datasets that have been rigorously anonymized or446de-identified to ensure the protection of individual research participants and447patient privacy448 449## Implementation information450 451Details about the model internals.452 453### Software454 455Training was done using [JAX](https://github.com/jax-ml/jax).456 457JAX allows researchers to take advantage of the latest generation of hardware,458including TPUs, for faster and more efficient training of large models.459 460## Use and limitations461 462### Intended use463 464MedGemma is an open multimodal generative AI model intended to be used as a465starting point that enables more efficient development of downstream healthcare466applications involving medical text and images. MedGemma is intended for467developers in the life sciences and healthcare space. Developers are responsible468for training, adapting and making meaningful changes to MedGemma to accomplish469their specific intended use. MedGemma models can be fine-tuned by developers470using their own proprietary data for their specific tasks or solutions.471 472MedGemma is based on Gemma 3 and has been further trained on medical images and473text. MedGemma enables further development in any medical context (image and474textual), however the model was pre-trained using chest X-ray, pathology,475dermatology, and fundus images. Examples of tasks within MedGemma's training476include visual question answering pertaining to medical images, such as477radiographs, or providing answers to textual medical questions. Full details of478all the tasks MedGemma has been evaluated can be found in an upcoming technical479report.480 481### Benefits482 483*   Provides strong baseline medical image and text comprehension for models of484    its size.485*   This strong performance makes it efficient to adapt for downstream486    healthcare-based use cases, compared to models of similar size without487    medical data pre-training.488*   This adaptation may involve prompt engineering, grounding, agentic489    orchestration or fine-tuning depending on the use case, baseline validation490    requirements, and desired performance characteristics.491 492### Limitations493 494MedGemma is not intended to be used without appropriate validation, adaptation495and/or making meaningful modification by developers for their specific use case.496The outputs generated by MedGemma are not intended to directly inform clinical497diagnosis, patient management decisions, treatment recommendations, or any other498direct clinical practice applications. Performance benchmarks highlight baseline499capabilities on relevant benchmarks, but even for image and text domains that500constitute a substantial portion of training data, inaccurate model output is501possible. All outputs from MedGemma should be considered preliminary and require502independent verification, clinical correlation, and further investigation503through established research and development methodologies.504 505MedGemma's multimodal capabilities have been primarily evaluated on single-image506tasks. MedGemma has not been evaluated in use cases that involve comprehension507of multiple images.508 509MedGemma has not been evaluated or optimized for multi-turn applications.510 511MedGemma's training may make it more sensitive to the specific prompt used than512Gemma 3.513 514When adapting MedGemma developer should consider the following:515 516*   **Bias in validation data:** As with any research, developers should ensure517    that any downstream application is validated to understand performance using518    data that is appropriately representative of the intended use setting for519    the specific application (e.g., age, sex, gender, condition, imaging device,520    etc).521*   **Data contamination concerns**: When evaluating the generalization522    capabilities of a large model like MedGemma in a medical context, there is a523    risk of data contamination, where the model might have inadvertently seen524    related medical information during its pre-training, potentially525    overestimating its true ability to generalize to novel medical concepts.526    Developers should validate MedGemma on datasets not publicly available or527    otherwise made available to non-institutional researchers to mitigate this528    risk.