CoolFace
Modelpublic

Machlovi/Phi4_MedQA_USMLE_4_Options

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
Model Card

Model Card for Model ID

<!-- Provide a quick summary of what the model is/does. -->

Model Details

Model Description

<!-- Provide a longer summary of what this model is. -->

This is the model card of a ๐Ÿค— transformers model that has been pushed on the Hub. This model card has been automatically generated.

  • โ€”Developed by: [More Information Needed]
  • โ€”Funded by [optional]: [More Information Needed]
  • โ€”Shared by [optional]: [More Information Needed]
  • โ€”Model type: [More Information Needed]
  • โ€”Language(s) (NLP): [More Information Needed]
  • โ€”License: [More Information Needed]
  • โ€”Finetuned from model [optional]: [More Information Needed]

Model Sources [optional]

<!-- Provide the basic links for the model. -->

  • โ€”Repository: [More Information Needed]
  • โ€”Paper [optional]: [More Information Needed]
  • โ€”Demo [optional]: [More Information Needed]

Uses

<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->

Direct Use

<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->

[More Information Needed]

Downstream Use [optional]

<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->

[More Information Needed]

Out-of-Scope Use

<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->

[More Information Needed]

Bias, Risks, and Limitations

<!-- This section is meant to convey both technical and sociotechnical limitations. -->

[More Information Needed]

Recommendations

<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.

How to Get Started with the Model

๐Ÿš€ How to Use This Model for Inference

This model is fine-tuned using LoRA (PEFT) on Phi-4 (4-bit Unsloth). To use it, you need to:

  1. 1.Load the base model
  2. 2.Load the LoRA adapter
  3. 3.Run inference

๐Ÿ“Œ Install Required Libraries

Before running the code, make sure you have the necessary dependencies installed:

pip install unsloth peft transformers torch

from unsloth import FastLanguageModel
from peft import PeftModel
import torch

# Load the base model
base_model_name = "unsloth/Phi-4-unsloth-bnb-4bit"
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name=base_model_name,
    max_seq_length=4096,  # Must match fine-tuning
    load_in_4bit=True,
)

# Load the fine-tuned LoRA adapter
lora_model_name = "Machlovi/Phi4_MedQA_USMLE_4_Options"
model = PeftModel.from_pretrained(model, lora_model_name)

# Run inference
input_text = "What are the symptoms of a heart attack?"
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=100)

# Decode and print response
response = tokenizer.decode(outputs[0], skip_special_tokens=True)

๐Ÿ’ก Notes

  • โ€”This model is quantized in 4-bit for efficiency.
  • โ€”Ensure max_seq_length matches the training configuration.
  • โ€”This model requires a GPU (CUDA) for inference.

[More Information Needed]

Training Details

Training Data

<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->

[More Information Needed]

Training Procedure

<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->

Preprocessing [optional]

[More Information Needed]

Training Hyperparameters
  • โ€”Training regime: [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
Speeds, Sizes, Times [optional]

<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->

[More Information Needed]

Evaluation

python

medmcqa = """< |im_start| > system 
You are a medical doctor answering real-world medical entrance exam questions. 
Based on your understanding of basic and clinical science, medical knowledge, and mechanisms underlying health, disease, 
patient care, and modes of therapy, answer the following multiplechoice question. 
Select one correct answer from A to D. Base your answer on the current and standard practices referenced in medical guidelines. < |im_end| >

< |im_start| > 
question: {}
options:{}
< |im_end| > 

< |im_start| >
answer:{}

๐Ÿ“ Example Inference

< |im_start| > system 
You are a medical doctor answering real-world medical entrance exam questions. 
Based on your understanding of basic and clinical science, medical knowledge, and mechanisms underlying health, disease, 
patient care, and modes of therapy, answer the following multiple-choice question. 
Select one correct answer from A to D. Base your answer on the current and standard practices referenced in medical guidelines. 
< |im_end| >

< |im_start| > 
question: A junior orthopaedic surgery resident is completing a carpal tunnel repair with the department chairman as the attending physician. 
During the case, the resident inadvertently cuts a flexor tendon. The tendon is repaired without complication. 
The attending tells the resident that the patient will do fine, and there is no need to report this minor complication that will not harm the patient, 
as he does not want to make the patient worry unnecessarily. He tells the resident to leave this complication out of the operative report. 
Which of the following is the correct next action for the resident to take?

options:
A. Disclose the error to the patient and put it in the operative report  
B. Tell the attending that he cannot fail to disclose this mistake  
C. Report the physician to the ethics committee  
D. Refuse to dictate the operative report  

< |im_end| >

< |im_start| >
answer: B. Tell the attending that he cannot fail to disclose this mistake
< |im_end| >

Testing Data, Factors & Metrics

Testing Data

<!-- This should link to a Dataset Card if possible. -->

[More Information Needed]

Factors

<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->

[More Information Needed]

Metrics

<!-- These are the evaluation metrics being used, ideally with a description of why. -->

[More Information Needed]

Results

[More Information Needed]

Summary

Model Examination [optional]

<!-- Relevant interpretability work for the model goes here -->

[More Information Needed]

Environmental Impact

<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->

Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).

  • โ€”Hardware Type: [More Information Needed]
  • โ€”Hours used: [More Information Needed]
  • โ€”Cloud Provider: [More Information Needed]
  • โ€”Compute Region: [More Information Needed]
  • โ€”Carbon Emitted: [More Information Needed]

Technical Specifications [optional]

Model Architecture and Objective

[More Information Needed]

Compute Infrastructure

[More Information Needed]

Hardware

[More Information Needed]

Software

[More Information Needed]

Citation [optional]

<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->

BibTeX:

[More Information Needed]

APA:

[More Information Needed]

Glossary [optional]

<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->

[More Information Needed]

More Information [optional]

[More Information Needed]

Model Card Authors [optional]

[More Information Needed]

Model Card Contact

[More Information Needed]