aashish1904 commited on
Commit
9a9c61a
·
verified ·
1 Parent(s): 0260a80

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +120 -0
README.md ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ library_name: transformers
5
+ license: mit
6
+ tags:
7
+ - medical
8
+ - biomedical
9
+ - process-reward-model
10
+ - medical-ai
11
+ - retrieval-augmented-generation
12
+ pipeline_tag: text-generation
13
+
14
+ ---
15
+
16
+ [![QuantFactory Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)
17
+
18
+
19
+ # QuantFactory/llama-3.1-medprm-reward-v1.0-GGUF
20
+ This is quantized version of [dmis-lab/llama-3.1-medprm-reward-v1.0](https://huggingface.co/dmis-lab/llama-3.1-medprm-reward-v1.0) created using llama.cpp
21
+
22
+ # Original Model Card
23
+
24
+
25
+ # Med-PRM-Reward (Version 1.0)
26
+ 🚀 Med-PRM-Reward is among the first Process Reward Models (PRMs) specifically designed for the medical domain. Unlike conventional PRMs, it enhances its verification capabilities by integrating clinical knowledge through retrieval-augmented generation (RAG). Med-PRM-Reward demonstrates exceptional performance in scaling-test-time computation, particularly outperforming majority‐voting ensembles on complex medical reasoning tasks. Moreover, its scalability is not limited to Llama-3.1-8B-Instruct: it delivers similarly outstanding results in scaling-test-time computation across multiple other medical‐specialized models. Notably, when combined with llama-3-meerkat-8b-v1.0, it became the first 8B model framework to surpass a score of 80 on the MedQA (4-option) benchmark.
27
+
28
+ 📄 Paper: [Med-PRM-Reward: Medical Reasoning Models with Stepwise, Guideline‑verified Process Rewards](https://huggingface.co/papers/2506.11474)
29
+
30
+ ## Quick Start
31
+ ```python
32
+ from transformers import AutoModelForCausalLM, AutoTokenizer
33
+ import torch
34
+
35
+ model_id = "dmis-lab/llama-3.1-medprm-reward-v1.0"
36
+ device = "cuda" if torch.cuda.is_available() else "cpu"
37
+
38
+ model = AutoModelForCausalLM.from_pretrained(
39
+ model_id,
40
+ torch_dtype=torch.bfloat16,
41
+ device_map="auto"
42
+ ).to(device)
43
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
44
+
45
+
46
+ plus_id = tokenizer(" +", add_special_tokens=False)["input_ids"][0]
47
+ minus_id = tokenizer(" -", add_special_tokens=False)["input_ids"][0]
48
+
49
+ def get_prob(text: str, special_char: str = " ки"):
50
+ encoded = tokenizer(text, return_tensors="pt", add_special_tokens=True)
51
+ input_ids = encoded["input_ids"].to(device)
52
+ attention_mask = encoded["attention_mask"].to(device)
53
+ with torch.no_grad():
54
+ logits = model(input_ids, attention_mask=attention_mask).logits[0]
55
+ offsets = tokenizer(text, return_offsets_mapping=True)["offset_mapping"]
56
+ positions = [
57
+ i for i, (s, e) in enumerate(offsets[0])
58
+ if text[s:e] == special_char
59
+ ]
60
+ plus_probs = []
61
+ for pos in positions:
62
+ if pos < logits.size(0):
63
+ pair = torch.stack([logits[pos][plus_id], logits[pos][minus_id]])
64
+ probs = torch.softmax(pair, dim=0)
65
+ plus_probs.append(probs[0].item())
66
+ min_plus = min(plus_probs) if plus_probs else None
67
+ final_plus = plus_probs[-1] if plus_probs else None
68
+ return {
69
+ "plus_probs": plus_probs,
70
+ "min_plus_prob": min_plus,
71
+ "final_plus_prob": final_plus
72
+ }
73
+
74
+
75
+ docs = ["Document 1: Causes of Posterior Urethral Valves. The valves can block the outflow of urine through the urethra, leading to damage in the bladder, ureters and kidneys. However, it is important to note that PUV occurs randomly by chance and is not caused by anything a mother did or did not do during pregnancy.In the womb, if the baby is unable to urinate due to PUV, there might be a deficiency in amniotic fluid, known as oligohydramnios. A major concern for oligohydramnios is the lack of proper lung development, called lung hypoplasia",
76
+ "Document 2: Amniotic Fluid Index -- Pathophysiology -- Polyhydramnios. Polyhydramnios, or increased amniotic fluid volume, also has a number of potential causes, with two primary common mechanisms: decreased fetal swallowing of amniotic fluid, or increased fetal production of amniotic fluid"]
77
+ question = ("A 29-year-old G1P0 female presents at 22 weeks gestation for her first prenatal care appointment. Physical exam demonstrates a uterine size greater than expected for her gestational age and taut, shiny skin with scattered striae on her abdomen. Ultrasound examination of the fetus reveals 2.5 L of amniotic fluid (normal 1.5-2.0 L) with an amniotic fluid index (AFI) of 34 (normal AFI 20-25). Which of the following fetal abnormalities or dysfunctions could have contributed to these abnormal ultrasound findings?
78
+
79
+ (A) Renal agenesis
80
+ (B) Pulmonary hypoplasia
81
+ (C) Duodenal atresia
82
+ (D) Posterior urethral valve
83
+ (E) Polycystic kidney disease")
84
+ explanation = ("Step 1: The patient's uterine size is greater than expected for her gestational age, which could indicate an issue with fetal growth, such as macrosomia or polyhydramnios. ки Step 2: The physical examination of the patient reveals taut, shiny skin with scattered striae on her abdomen, which is indicative of rapid weight gain, often associated with polyhydramnios. ки Step 3: The ultrasound findings show an increased volume of amniotic fluid of 2.5 L, which is above the normal range of 1.5-2.0 L, and an amniotic fluid index (AFI) of 34, also higher than the normal range of 20-25. ки Step 4: Polyhydramnios is characterized by an excessive accumulation of amniotic fluid, and it is often associated with fetal or maternal conditions that limit fetal swallowing or increase fetal urine production. ки Step 5: Among the available options, posterior urethral valve (D) is a condition where the urethra is partially blocked, leading to an obstruction in the urinary tract, which can result in increased fetal urine production and subsequent polyhydramnios. ки Step 6: Considering the options provided, posterior urethral valve is a condition that could have contributed to the abnormal ultrasound findings due to its association with increased fetal urine production and polyhydramnios. The answer is D. ки")
85
+
86
+ doc_block = "
87
+
88
+ ".join(docs) + "
89
+
90
+ "
91
+ user_content = f"{doc_block}Question: {question}
92
+
93
+ Explanation: {explanation}"
94
+ system_prompt = (
95
+ "You are an evaluator assessing the logicality and validity of the reasoning in each step of the given explanation. "
96
+ "In order to support the evaluation, the relevant documents, the question, and the explanation are provided sequentially. "
97
+ "If the reasoning contains errors, output - after that step. If the reasoning in a step is logical and valid, output + after that step. "
98
+ )
99
+ raw = tokenizer.apply_chat_template(
100
+ [{"role": "system", "content": system_prompt},
101
+ {"role": "user", "content": user_content}],
102
+ tokenize=False,
103
+ add_generation_prompt=True
104
+ )
105
+
106
+ scores = get_prob(raw)
107
+ print("Plus probabilities per step:", scores["plus_probs"])
108
+ print("Min plus probability :", scores["min_plus_prob"])
109
+ print("Final plus probability :", scores["final_plus_prob"])
110
+ ```
111
+
112
+ ## Evaluation
113
+ Across seven medical benchmarks, we conducted scaling‐test‐time computation using solutions generated by the Med-PRM-policy model, evaluating 64 solutions per question.
114
+
115
+ ### Reference
116
+
117
+ ## Acknowledgement
118
+
119
+ ## Contact
120
+ Feel free to email [email protected] if you have any questions.