惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
B
Blog
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
A
About on SuperTechFans
H
Heimdal Security Blog
AI
AI
F
Full Disclosure
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
量子位
I
InfoQ
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
N
News and Events Feed by Topic
腾讯CDC
L
LINUX DO - 最新话题
Attack and Defense Labs
Attack and Defense Labs
Hacker News: Ask HN
Hacker News: Ask HN
Google Online Security Blog
Google Online Security Blog
博客园_首页
Forbes - Security
Forbes - Security
The Register - Security
The Register - Security
博客园 - 三生石上(FineUI控件)
PCI Perspectives
PCI Perspectives
V
Vulnerabilities – Threatpost
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LangChain Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
NISL@THU
NISL@THU
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
H
Hacker News: Front Page
Project Zero
Project Zero
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - VipSoft

MinerU - 将非结构化文档(PDF、图片、Office 文件等)转换为机器可读的 Markdown 和 JSON LangChain 入门 服务端部署-FastAPI LangChain 入门 LangSmith LangChain 入门 实战 - 食谱推荐 LangChain 入门 Memory 会话记忆 LangChain 入门 Tools 工具 LangChain 入门 Tools 工具 LangChain 入门 Prompts 提示词 LangChain 入门 Message 消息 LangChain 入门 Model 的初始化和调用 LangChain 入门 Agent 的基本运行机制 AI 0基础学习,名词解析 LangChain 和 LangGraph AI大模型知识体系 Dify — Workflow - 数据可视化 Dify — 连接MySQL配置 Dify — Chatflow - 数据库智能查询 Dify — Chatflow - 文档知识库 Dify — Agent 智能体 高安全券码、注册码生成 Dify — 文本生成应用 Dify — 聊天助手 -- 知识库 Windows 下 Docker 安装 Dify Ollama — 命令 Ollama — 为什么能够运行不同的模型 Ollama — 接口 Qwen — 自定义模型文件 Ollama Qwen — 安装测试 Ollama Windows 安装 & 指定安装目录 跟着AI学AI - 诊断结论信息抽取 - 模型压缩与部署 跟着AI学AI - 诊断结论信息抽取 - 模型评估与调试 跟着AI学AI - 诊断结论信息抽取 - 模型训练 轻型民用无人驾驶航空器安全操控理论考试培训材料 FreeRedis Helper Windbg w3wp.DMP 内存分析 跟着AI学AI - 诊断结论信息抽取 - 数据增强 QQ 录屏软件 Java - 加权随机算法 - 示例 Java - 加权随机算法--Demo Java LoadBalanceUtil 负载均衡、轮询加权 SpringBoot 集成 IP2Region 获取IP地域信息 Windows 服务器和虚拟主机,创建.开头的文件夹 .well-known 跟着AI学AI - 诊断结论信息抽取 - 数据格式转换BERT训练格式 跟着AI学AI - 诊断结论信息抽取 - LabelStudio 标注 -- 结论标注 跟着AI学AI - 诊断结论信息抽取 - 学习路径 跟着AI学AI - UV 安装 数据标注工具 Label-Studio `VIRTUAL_ENV=venv` does not match the project environment 跟着AI学AI - 学习路径 - 命名实体识别(NER)和信息抽取(IE) 跟着AI学AI - 需要购买显卡吗? C# 无BOM的UTF-8编码 Vue ref reactive Vue - el-table 嵌套表 Spring `@Scheduled` 中这些参数的区别、组合和应用场景 Python 找出同步日志中的重复数据 Python - UV PyCharm 不能识别 .venv 的环境
跟着AI学AI - 诊断结论信息抽取 - 批量处理脚本
VipSoft · 2026-05-11 · via 博客园 - VipSoft

批量处理脚本

batch_process.py

# batch_process.py
import json
import os
from tqdm import tqdm
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed

class BatchNERProcessor:
    def __init__(self, api_url='http://localhost:8000/predict'):
        self.api_url = api_url
    
    def process_single(self, report):
        """处理单个报告"""
        try:
            response = requests.post(
                self.api_url,
                json={'text': report['text'], 'report_id': report.get('id')}
            )
            if response.status_code == 200:
                return response.json()
            else:
                return None
        except Exception as e:
            print(f"处理失败: {e}")
            return None
    
    def process_batch(self, reports, max_workers=4):
        """批量处理报告"""
        results = []
        
        with ThreadPoolExecutor(max_workers=max_workers) as executor:
            futures = {executor.submit(self.process_single, report): report for report in reports}
            
            for future in tqdm(as_completed(futures), total=len(reports), desc="处理报告"):
                result = future.result()
                if result:
                    results.append(result)
        
        return results
    
    def process_file(self, input_file, output_file):
        """处理文件中的报告"""
        print(f"读取文件: {input_file}")
        with open(input_file, 'r', encoding='utf-8') as f:
            reports = json.load(f)
        
        print(f"处理 {len(reports)} 个报告...")
        results = self.process_batch(reports)
        
        print(f"保存结果到: {output_file}")
        with open(output_file, 'w', encoding='utf-8') as f:
            json.dump(results, f, indent=2, ensure_ascii=False)
        
        return results

# 使用示例
if __name__ == "__main__":
    processor = BatchNERProcessor()
    
    # 处理新报告
    new_reports = [
        {"id": "001", "text": "平均心率为82次/分,最快心率是158次/分..."},
        {"id": "002", "text": "心率监测:平均68次/分,最高132次/分..."}
    ]
    
    results = processor.process_batch(new_reports)
    
    for result in results:
        print(f"\n报告 {result['report_id']}:")
        print(f"实体数: {len(result['entities'])}")
        print(f"摘要: {result['summary']}")

持续优化流程

# continuous_improvement.py
class ActiveLearning:
    """主动学习循环"""
    
    def __init__(self, model_path, unlabeled_data_path):
        self.model_path = model_path
        self.unlabeled_data = self.load_unlabeled_data(unlabeled_data_path)
        self.ner_service = NERService(model_path)
    
    def load_unlabeled_data(self, path):
        with open(path, 'r', encoding='utf-8') as f:
            return json.load(f)
    
    def calculate_uncertainty(self, text):
        """计算模型的不确定性"""
        # 使用模型预测概率的熵作为不确定性度量
        # 实现细节...
        return uncertainty_score
    
    def select_samples_to_label(self, n_samples=10):
        """选择最有价值的样本进行人工标注"""
        uncertainties = []
        for report in self.unlabeled_data:
            uncertainty = self.calculate_uncertainty(report['text'])
            uncertainties.append((report, uncertainty))
        
        # 选择不确定性最高的n个样本
        uncertainties.sort(key=lambda x: x[1], reverse=True)
        return [report for report, _ in uncertainties[:n_samples]]
    
    def retrain_model(self, new_labeled_data):
        """使用新标注数据重新训练模型"""
        # 合并新旧标注数据
        # 重新训练
        pass

# 定时重训练脚本
def scheduled_retraining():
    """定期重新训练模型"""
    import schedule
    import time
    
    def retrain_job():
        print(f"{datetime.now()}: 开始重新训练模型")
        # 1. 收集新标注数据
        # 2. 重新训练
        # 3. 评估效果
        # 4. 部署新模型
        pass
    
    # 每周一凌晨3点重新训练
    schedule.every().monday.at("03:00").do(retrain_job)
    
    while True:
        schedule.run_pending()
        time.sleep(60)
ecg_ner_project/
├── data/
│   ├── raw/                    # 原始数据
│   ├── labeled/                # 标注数据
│   └── out/                    # 转换后的数据
├── models/
│   └── ecg_ner_model/          # 训练好的模型
├── src/
│   ├── data_preparation.py     # 数据准备
│   ├── train_model.py          # 模型训练
│   ├── evaluate_model.py       # 模型评估
│   ├── ner_service.py          # API服务
│   ├── batch_process.py        # 批量处理
│   └── continuous_improvement.py # 持续优化
├── scripts/
│   ├── run_training.sh         # 训练脚本
│   ├── run_api.sh              # 启动API
│   └── batch_predict.py        # 批量预测
├── tests/
│   ├── test_model.py           # 模型测试
│   └── test_api.py             # API测试
├── requirements.txt            # 依赖包
├── config.yaml                 # 配置文件
└── README.md                   # 项目说明

快速启动命令

# 1. 训练模型
python src/train_model.py

# 2. 启动API服务
uvicorn src.ner_service:app --reload --port 8000

# 3. 测试API
curl -X POST "http://localhost:8000/predict" \
     -H "Content-Type: application/json" \
     -d '{"text":"平均心率为76次/分"}'

# 4. 批量处理
python scripts/batch_predict.py --input data/new_reports.json --output results.json