Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions runtime/ops/mapper/medcleanstd_operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# MedCleanStd 医疗文本清洗标准化算子

## 概述

MedCleanStd 是一个面向医疗文本的智能化清洗与标准化处理算子,集成了文档解析、文本纠错、命名实体识别(NER)和医学术语标准化四大核心功能。

## 功能特性

### 1. 文档解析
- 支持 `.docx`和`.txt` 格式医疗文档
- 段落提取与表格线性化处理
- 字符位置映射构建,支持实体溯源

### 2. 文本纠错
- 混淆集快速匹配(<1ms)
- 可选拼音纠错(ProperCorrector)
- 智能分段处理长文本

### 3. 实体识别
- 基于 SiameseUIE 模型
- 支持多种实体类型:疾病、症状、药品、手术、检查、检验
- NPU/GPU/CPU 多硬件平台自适应

### 4. 术语标准化
- L1 缓存:高频词精确匹配
- L2 向量检索:语义模糊匹配
- 输出 ICD-10 标准编码

## 参数说明

| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| 启用拼音纠错 | switch | false | 是否启用拼音纠错(精度更高但速度较慢) |
| 启用 L1 缓存 | switch | true | 是否启用高频术语 L1 缓存 |
| NER 抽取目标 | checkbox | 疾病,症状 | 选择需要抽取的实体类型 |
| 分句块大小 | slider | 10 | 每个处理 chunk 包含的最大句子数 |
| 标准化批大小 | slider | 24 | 术语标准化时的向量编码批处理大小 |
| 最大实体长度 | slider | 50 | 超过此长度的实体将被过滤 |

## 输入输出

**输入**: 文本数据(`text` 字段)

**输出**: 包含以下字段:
- `corrected_text`: 纠错后的文本
- `correction_errors`: 纠错明细
- `entities`: 识别的实体列表
- `filtered_entities`: 过滤后的实体列表(含标准化结果)
- `medclean_metadata`: 处理元数据

## 实体输出格式

```json
{
"text": "急性阑尾炎",
"type": "疾病",
"start": 2,
"end": 7,
"global_start": 2,
"global_end": 7,
"normalized": {
"std_name": "急性阑尾炎",
"std_code": "K35.900",
"score": 1.0,
"source": "L1_Cache"
}
}
```

## 依赖说明

- torch >= 2.0.0
- torch_npu >= 2.1.0 (NPU 设备可选)
- modelscope >= 1.9.0
- python-docx >= 0.8.11
- pycorrector >= 0.4.5
- sentence-transformers >= 2.2.0
- faiss-cpu >= 1.7.4

## 使用示例

```python
# 输入
sample = {
"text": "患者急性阑尾炎伴右下腹痛,建议服用头孢拉定。"
}

# 输出
sample = {
"text": "患者急性阑尾炎伴右下腹痛,建议服用头孢拉定。",
"corrected_text": "患者急性阑尾炎伴右下腹痛,建议服用头孢拉定。",
"entities": [
{"text": "急性阑尾炎", "type": "疾病", ...},
{"text": "右下腹痛", "type": "症状", ...},
{"text": "头孢拉定", "type": "药品", ...}
],
...
}
```

## 版本历史

- **v1.0.0**: 首次发布,支持基本医疗文本清洗与标准化功能
11 changes: 11 additions & 0 deletions runtime/ops/mapper/medcleanstd_operator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
"""
MedCleanStd 医疗文本清洗标准化算子注册入口
"""

from datamate.core.base_op import OPERATORS

OPERATORS.register_module(
module_name='MedCleanStdMapper',
module_path="ops.user.medcleanstd_operator.process"
)
88 changes: 88 additions & 0 deletions runtime/ops/mapper/medcleanstd_operator/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: '医疗文本清洗标准化算子'
description: 'MedCleanStd 是一个面向医疗文本的智能化清洗与标准化处理系统,集成了文档解析、文本纠错、命名实体识别(NER)和医学术语标准化四大核心功能。'
language: 'python'
vendor: 'huawei'
raw_id: 'MedCleanStdMapper'
version: '1.0.0'
modal: 'text'
inputs: 'text'
outputs: 'text'
release:
- '首次发布:医疗文本清洗与标准化处理'
- '支持文档解析、文本纠错、NER 实体识别、术语标准化'
- '支持 NPU/GPU/CPU多硬件平台自适应'
metrics:
- name: '准确率'
metric: '95.0%'
- name: '处理速度'
metric: '300 ms/doc'
- name: '内存使用'
metric: '512MB'
- name: '吞吐量'
metric: '3 docs/sec'
runtime:
memory: 536870912
cpu: 0.5
gpu: 0.1
npu: 0.1
storage: 1GB
settings:
use_proper_corrector:
name: '启用拼音纠错'
description: '是否启用 ProperCorrector 进行拼音和错别字纠正(开启后精度更高但速度较慢,约 600ms/次)'
type: 'switch'
defaultVal: 'false'
required: false
checkedLabel: '已启用'
unCheckedLabel: '未启用'
use_l1_cache:
name: '启用 L1 缓存'
description: '是否启用高频术语 L1 缓存(开启后高频词处理速度提升至<1ms)'
type: 'switch'
defaultVal: 'true'
required: false
checkedLabel: '已启用'
unCheckedLabel: '未启用'
ner_schema:
name: 'NER 抽取目标'
description: '选择需要抽取的实体类型'
type: 'checkbox'
defaultVal: '疾病,症状'
required: true
options:
- label: '疾病'
value: '疾病'
- label: '症状'
value: '症状'
- label: '药品'
value: '药品'
- label: '手术'
value: '手术'
- label: '检查'
value: '检查'
- label: '检验'
value: '检验'
max_sentences:
name: '分句块大小'
description: '每个处理 chunk 包含的最大句子数(影响处理粒度和内存占用)'
type: 'slider'
defaultVal: 10
min: 5
max: 40
step: 1
normalizer_batch_size:
name: '标准化批大小'
description: '术语标准化时的向量编码批处理大小(NPU 设备可调大)'
type: 'slider'
defaultVal: 24
min: 8
max: 64
step: 8
max_entity_length:
name: '最大实体长度'
description: '超过此长度的实体将被过滤(避免输出过长实体)'
type: 'slider'
defaultVal: 50
min: 20
max: 100
step: 5
Loading