Update README.md
Browse files
README.md
CHANGED
@@ -9,6 +9,11 @@ base_model:
|
|
9 |
- Qwen/Qwen2.5-0.5B
|
10 |
---
|
11 |
# Qwen2.5-med-book-main-classification
|
|
|
|
|
|
|
|
|
|
|
12 |
The model is an intermediate product of the [EPCD (Easy-Data-Clean-Pipeline)](https://github.com/ytzfhqs/EDCP) project, primarily used to distinguish between the main content and non-content (such as book introductions, publisher information, writing standards, revision notes) of **medical textbooks** after performing OCR using [MinerU](https://github.com/opendatalab/MinerU). The base model uses [Qwen2.5-0.5B](https://huggingface.co/Qwen/Qwen2.5-0.5B), avoiding the length limitation of the Bert Tokenizer while providing higher accuracy.
|
13 |
|
14 |
# Data Composition
|
@@ -72,6 +77,84 @@ model = AutoModelForSequenceClassification.from_pretrained(
|
|
72 |
)
|
73 |
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left")
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
text = ['下列为修订说明','阴离子间隙是一项受到广泛重视的酸碱指标。AG是一个计算值,指血浆中未测定的阴离子与未测定的阳离子的差值,正常机体血浆中的阳离子与阴离子总量相等,均为151mmol/L,从而维持电荷平衡。']
|
76 |
encoding = tokenizer(text, return_tensors='pt',padding=True)
|
77 |
encoding = {k: v.to(model.device) for k, v in encoding.items()}
|
|
|
9 |
- Qwen/Qwen2.5-0.5B
|
10 |
---
|
11 |
# Qwen2.5-med-book-main-classification
|
12 |
+
|
13 |
+
[[中文]](#chinese) [[English]](#english)
|
14 |
+
|
15 |
+
<a id="english"></a>
|
16 |
+
|
17 |
The model is an intermediate product of the [EPCD (Easy-Data-Clean-Pipeline)](https://github.com/ytzfhqs/EDCP) project, primarily used to distinguish between the main content and non-content (such as book introductions, publisher information, writing standards, revision notes) of **medical textbooks** after performing OCR using [MinerU](https://github.com/opendatalab/MinerU). The base model uses [Qwen2.5-0.5B](https://huggingface.co/Qwen/Qwen2.5-0.5B), avoiding the length limitation of the Bert Tokenizer while providing higher accuracy.
|
18 |
|
19 |
# Data Composition
|
|
|
77 |
)
|
78 |
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left")
|
79 |
|
80 |
+
text = ['下列为修订说明','阴离子间隙是一项受到广泛重视的酸碱指标。AG是一个计算值,指血浆中未测定的阴离子与未测定的阳离子的差值,正常机体血浆中的阳离子与阴离子总量相等,均为151mmol/L,从而维持电荷平衡。']
|
81 |
+
encoding = tokenizer(text, return_tensors='pt',padding=True)
|
82 |
+
encoding = {k: v.to(model.device) for k, v in encoding.items()}
|
83 |
+
outputs = model(**encoding)
|
84 |
+
logits = outputs.logits
|
85 |
+
ids = torch.argmax(logits, dim=-1).tolist()
|
86 |
+
response = [ID2LABEL[id] for id in ids]
|
87 |
+
print(response)
|
88 |
+
# ['非正文', '正文']
|
89 |
+
```
|
90 |
+
|
91 |
+
# Qwen2.5-med-book-main-classification
|
92 |
+
|
93 |
+
[[中文]](#chinese) [[English]](#english)
|
94 |
+
|
95 |
+
<a id="chinese"></a>
|
96 |
+
|
97 |
+
该模型为[EPCD(Easy-Data-Clean-Pipeline)](https://github.com/ytzfhqs/EDCP)项目的中间产物,主要用来区分使用[MinerU](https://github.com/opendatalab/MinerU)进行OCR后的**医学教科书**的正文与非正文(书本简介、出版社信息、编写规范、修订说明)样本。基础模型使用[Qwen2.5-0.5B](https://huggingface.co/Qwen/Qwen2.5-0.5B),避免了Bert Tokenizer长度的限制,并且提供了更高的精度。
|
98 |
+
|
99 |
+
# 数据组成
|
100 |
+
|
101 |
+
- 数据由教科书PDF扫描件,经过[MinerU](https://github.com/opendatalab/MinerU)进行`OCR`后生成的`Markdown`文件。经过简单的正则化清洗,使用`\n`进行分割样本,经过`Bloom`概率过滤器精准去重,最终产生了5W条样本。由于涉及一些法律条款,我们可能没有计划公开数据集。
|
102 |
+
- 由于教科书的特性,样本大多为正文样本,根据统计,在我们的数据集中,正文样本占总样本的79.89%(4W条),非正文样本占总样本的20.13%(1W条)。由于数据的不平衡性,我们综合考虑模型在测试集上的Precision和Accuracy指标。
|
103 |
+
- 为了保证测试集与训练集数据分布一致,我们使用分层抽样,选取10%的数据构成测试集。
|
104 |
+
|
105 |
+
# 训练技巧
|
106 |
+
- 为了尽可能提高模型精度,我们使用了贝叶斯优化(TPE算法)和Hyperband修剪器(HyperbandPruner)加快模型调参效率。
|
107 |
+
|
108 |
+
# 模型表现
|
109 |
+
|Dataset | Accuracy | Precision |
|
110 |
+
|-------|-------|
|
111 |
+
|Train | 0.9894 | 0.9673 |
|
112 |
+
|Test | 0.9788 | 0.9548 |
|
113 |
+
|
114 |
+
# Usage
|
115 |
+
|
116 |
+
```python
|
117 |
+
import torch
|
118 |
+
from transformers import AutoModelForSequenceClassification
|
119 |
+
from transformers import AutoTokenizer
|
120 |
+
|
121 |
+
ID2LABEL = {0: "正文", 1: "非正文"}
|
122 |
+
|
123 |
+
model_name = 'ytzfhqs/Qwen2.5-med-book-main-classification'
|
124 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
125 |
+
model_name,
|
126 |
+
torch_dtype="auto",
|
127 |
+
device_map="auto"
|
128 |
+
)
|
129 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
130 |
+
|
131 |
+
text = '下列为修订说明'
|
132 |
+
encoding = tokenizer(text, return_tensors='pt')
|
133 |
+
encoding = {k: v.to(model.device) for k, v in encoding.items()}
|
134 |
+
outputs = model(**encoding)
|
135 |
+
logits = outputs.logits
|
136 |
+
id = torch.argmax(logits, dim=-1).item()
|
137 |
+
response = ID2LABEL[id]
|
138 |
+
print(response)
|
139 |
+
# "非正文"
|
140 |
+
```
|
141 |
+
|
142 |
+
# For Batch Usage
|
143 |
+
```python
|
144 |
+
import torch
|
145 |
+
from transformers import AutoModelForSequenceClassification
|
146 |
+
from transformers import AutoTokenizer
|
147 |
+
|
148 |
+
ID2LABEL = {0: "正文", 1: "非正文"}
|
149 |
+
|
150 |
+
model_name = 'ytzfhqs/Qwen2.5-med-book-main-classification'
|
151 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
152 |
+
model_name,
|
153 |
+
torch_dtype="auto",
|
154 |
+
device_map="auto"
|
155 |
+
)
|
156 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left")
|
157 |
+
|
158 |
text = ['下列为修订说明','阴离子间隙是一项受到广泛重视的酸碱指标。AG是一个计算值,指血浆中未测定的阴离子与未测定的阳离子的差值,正常机体血浆中的阳离子与阴离子总量相等,均为151mmol/L,从而维持电荷平衡。']
|
159 |
encoding = tokenizer(text, return_tensors='pt',padding=True)
|
160 |
encoding = {k: v.to(model.device) for k, v in encoding.items()}
|