WenchuanZhang commited on
Commit
b6f827f
·
verified ·
1 Parent(s): 5054746

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +126 -1
README.md CHANGED
@@ -7,4 +7,129 @@ library_name: transformers
7
  tags:
8
  - multimodal
9
  - Pathology
10
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  tags:
8
  - multimodal
9
  - Pathology
10
+ - arxiv:2505.11404
11
+ extra_gated_prompt: >-
12
+ The Patho-R1-3B 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-3B**, a multimodal pathology reasoner designed to enhance diagnostic understanding through structured reasoning. **Patho-R1-3B** 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 **Decoupled CLIP and Dynamic sAmpling Policy Optimization** to refine response quality
45
+
46
+ Experimental results show that **Patho-R1-3B** 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
+
48
+ ### Quickstart🏃
49
+ Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
50
+
51
+ ```python
52
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
53
+ from qwen_vl_utils import process_vision_info
54
+
55
+
56
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
57
+ "WenchuanZhang/Patho-R1-3B",
58
+ torch_dtype="auto", device_map="auto"
59
+ )
60
+ processor = AutoProcessor.from_pretrained("WenchuanZhang/Patho-R1-3B")
61
+
62
+ # example question from Pathmmu-test-dataset
63
+ # ground truth: D
64
+
65
+ messages = [
66
+ { "role": "system",
67
+ "content": [
68
+ {
69
+ "type": "image",
70
+ "image": "./images/241.jpg",
71
+ },
72
+ {"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>"},
73
+ ],
74
+
75
+ },
76
+ {
77
+ "role": "user",
78
+ "content": [
79
+ {
80
+ "type": "image",
81
+ "image": "./images/241.jpg",
82
+ },
83
+ {"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"},
84
+ ],
85
+ }
86
+ ]
87
+ # Preparation for inference
88
+ text = processor.apply_chat_template(
89
+ messages, tokenize=False, add_generation_prompt=True
90
+ )
91
+ image_inputs, video_inputs = process_vision_info(messages)
92
+ inputs = processor(
93
+ text=[text],
94
+ images=image_inputs,
95
+ videos=video_inputs,
96
+ padding=True,
97
+ return_tensors="pt",
98
+ )
99
+ inputs = inputs.to(model.device)
100
+
101
+ # Inference: Generation of the output
102
+ generated_ids = model.generate(**inputs, max_new_tokens=2048)
103
+ generated_ids_trimmed = [
104
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
105
+ ]
106
+ output_text = processor.batch_decode(
107
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
108
+ )
109
+ print(output_text)
110
+ ```
111
+ ## Acknowledgements🎖
112
+
113
+ We gratefully acknowledge the contributions of the open-source community, particularly the following projects which laid the foundation for various components of this work:
114
+
115
+ - [Qwen](https://github.com/QwenLM) for providing powerful vision language models that significantly advanced our multimodal understanding and generation capabilities.
116
+ - [DocLayout-YOLO](https://github.com/opendatalab/DocLayout-YOLO) for document layout detection.
117
+ - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) for comprehensive optical character recognition.
118
+ - [ModelScope Swift](https://github.com/modelscope/ms-swift) for efficient model serving and deployment tools.
119
+ - [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) for robust LLM training and fine-tuning pipelines.
120
+ - [VERL](https://github.com/volcengine/verl) for valuable visual-language pretraining resources.
121
+ - [DeepSeek](https://github.com/deepseek-ai) for high-quality models and infrastructure supporting text understanding.
122
+
123
+ We thank the authors and contributors of these repositories for their dedication and impactful work, which made our development of Patho-R1-3B possible.
124
+
125
+ ## Citation❤️
126
+ If you find our work helpful, a citation would be greatly appreciated:
127
+
128
+ ```
129
+ @article{zhang2025patho,
130
+ title={Patho-R1: A Multimodal Reinforcement Learning-Based Pathology Expert Reasoner},
131
+ 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},
132
+ journal={arXiv preprint arXiv:2505.11404},
133
+ year={2025}
134
+ }
135
+ ```