WenchuanZhang commited on
Commit
9d1e043
·
verified ·
1 Parent(s): 7b22d98

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +136 -3
README.md CHANGED
@@ -1,3 +1,136 @@
1
- ---
2
- license: cc-by-nc-nd-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-nd-4.0
3
+ language:
4
+ - en
5
+ pipeline_tag: image-text-to-text
6
+ library_name: transformers
7
+ tags:
8
+ - multimodal
9
+ - Pathology
10
+ - arxiv:2505.11404
11
+ extra_gated_prompt: >-
12
+ The Patho-R1-7B model and its associated materials are released under the CC-BY-NC-ND 4.0 license.
13
+ Access is restricted to non-commercial, academic research purposes only, with proper citation required.
14
+ Any commercial usage, redistribution, or derivative work (including training models based on this model or generating datasets from its outputs)
15
+ is strictly prohibited without prior written approval.
16
+
17
+ Users must register with an official institutional email address (generic domains such as @gmail, @qq, @hotmail, etc. will not be accepted).
18
+ By requesting access, you confirm that your information is accurate and current, and that you agree to comply with all terms listed herein.
19
+ If other members of your organization wish to use the model, they must register independently and agree to the same terms.
20
+
21
+ extra_gated_fields:
22
+ Full name (first and last): text
23
+ Institutional affiliation (no abbreviations): text
24
+ Role/Position:
25
+ type: select
26
+ options:
27
+ - Faculty/Principal Investigator
28
+ - PhD Student
29
+ - Postdoctoral Researcher
30
+ - Research Staff
31
+ - Other
32
+ Official institutional email (**must match your Hugging Face primary email; generic domains will be denied**): text
33
+ Intended research use (be specific): text
34
+ I agree to use this model only for non-commercial academic purposes: checkbox
35
+ I agree not to redistribute this model or share it outside of my individual usage: checkbox
36
+ I confirm that all submitted information is accurate and up to date: checkbox
37
+ ---
38
+ ## Introduction📝
39
+ While vision-language models have shown impressive progress in general medical domains, pathology remains a challenging subfield due to its high-resolution image requirements and complex diagnostic reasoning.
40
+
41
+ To address this gap, we introduce **Patho-R1-7B**, a multimodal pathology reasoner designed to enhance diagnostic understanding through structured reasoning. **Patho-R1-7B** is trained using a three-stage pipeline:
42
+ 1. *Continued pretraining* on **3.5M pathology figure-caption pairs** for domain knowledge acquisition
43
+ 2. *Supervised fine-tuning* on **500k expert-annotated Chain-of-Thought samples** to encourage reasoning
44
+ 3. *Reinforcement learning* with **Group Relative Policy Optimization** to refine response quality
45
+
46
+ Experimental results show that **Patho-R1-7B** achieves strong performance across key pathology tasks, including **multiple choice questions** and **visual question answering**, highlighting its potential for real-world pathology AI applications.
47
+ ![Patho-R1 Overview](https://github.com/Wenchuan-Zhang/Patho-R1/raw/main/docs/overview.png)
48
+
49
+ ### Quickstart🏃
50
+ Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
51
+
52
+ ```python
53
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
54
+ from qwen_vl_utils import process_vision_info
55
+
56
+
57
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
58
+ "WenchuanZhang/Patho-R1-7B",
59
+ torch_dtype="auto", device_map="auto"
60
+ )
61
+ processor = AutoProcessor.from_pretrained("WenchuanZhang/Patho-R1-7B")
62
+
63
+ # example question from Pathmmu-test-dataset
64
+ # ground truth: D
65
+
66
+ messages = [
67
+ { "role": "system",
68
+ "content": [
69
+ {
70
+ "type": "image",
71
+ "image": "./images/241.jpg",
72
+ },
73
+ {"type": "text", "text": "You are a pathology expert, your task is to answer question step by step. Use the following format:<think> Your step-by-step reasoning </think><answer> Your final answer </answer>"},
74
+ ],
75
+
76
+ },
77
+ {
78
+ "role": "user",
79
+ "content": [
80
+ {
81
+ "type": "image",
82
+ "image": "./images/241.jpg",
83
+ },
84
+ {"type": "text", "text": "What feature in the provided micrograph is indicative of chronic inflammation? /n A. Granuloma formation /n B. Multinucleated giant cells /n C. Neutrophilic infiltration /n D. Plasma cells with eccentrically placed nuclei"},
85
+ ],
86
+ }
87
+ ]
88
+ # Preparation for inference
89
+ text = processor.apply_chat_template(
90
+ messages, tokenize=False, add_generation_prompt=True
91
+ )
92
+ image_inputs, video_inputs = process_vision_info(messages)
93
+ inputs = processor(
94
+ text=[text],
95
+ images=image_inputs,
96
+ videos=video_inputs,
97
+ padding=True,
98
+ return_tensors="pt",
99
+ )
100
+ inputs = inputs.to(model.device)
101
+
102
+ # Inference: Generation of the output
103
+ generated_ids = model.generate(**inputs, max_new_tokens=2048)
104
+ generated_ids_trimmed = [
105
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
106
+ ]
107
+ output_text = processor.batch_decode(
108
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
109
+ )
110
+ print(output_text)
111
+ ```
112
+ ## Acknowledgements🎖
113
+
114
+ We gratefully acknowledge the contributions of the open-source community, particularly the following projects which laid the foundation for various components of this work:
115
+
116
+ - [Qwen](https://github.com/QwenLM) for providing powerful vision language models that significantly advanced our multimodal understanding and generation capabilities.
117
+ - [DocLayout-YOLO](https://github.com/opendatalab/DocLayout-YOLO) for document layout detection.
118
+ - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) for comprehensive optical character recognition.
119
+ - [ModelScope Swift](https://github.com/modelscope/ms-swift) for efficient model serving and deployment tools.
120
+ - [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) for robust LLM training and fine-tuning pipelines.
121
+ - [VERL](https://github.com/volcengine/verl) for valuable visual-language pretraining resources.
122
+ - [DeepSeek](https://github.com/deepseek-ai) for high-quality models and infrastructure supporting text understanding.
123
+
124
+ We thank the authors and contributors of these repositories for their dedication and impactful work, which made our development of Patho-R1-3B possible.
125
+
126
+ ## Citation❤️
127
+ If you find our work helpful, a citation would be greatly appreciated:
128
+
129
+ ```
130
+ @article{zhang2025patho,
131
+ title={Patho-R1: A Multimodal Reinforcement Learning-Based Pathology Expert Reasoner},
132
+ author={Zhang, Wenchuan and Zhang, Penghao and Guo, Jingru and Cheng, Tao and Chen, Jie and Zhang, Shuwan and Zhang, Zhang and Yi, Yuhao and Bu, Hong},
133
+ journal={arXiv preprint arXiv:2505.11404},
134
+ year={2025}
135
+ }
136
+ ```