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

推荐订阅源

Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
MyScale Blog
MyScale Blog
G
GRAHAM CLULEY
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
Y
Y Combinator Blog
The Register - Security
The Register - Security
宝玉的分享
宝玉的分享
S
Schneier on Security
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
G
Google Developers Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
S
Security @ Cisco Blogs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
M
MIT News - Artificial intelligence
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
W
WeLiveSecurity
Latest news
Latest news
博客园 - 【当耐特】
P
Palo Alto Networks Blog
博客园 - 叶小钗
Simon Willison's Weblog
Simon Willison's Weblog
Jina AI
Jina AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Troy Hunt's Blog
L
LangChain Blog
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
C
Check Point Blog
O
OpenAI News
C
Cisco Blogs
T
Tor Project blog
A
About on SuperTechFans
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
Attack and Defense Labs
Attack and Defense Labs

博客园 - VipSoft

Python 项目简单部署(Linux) 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
# 设置镜像源的环境变量
(vippython) PS D:\OpenSource\Python\VipPython> $env:HF_ENDPOINT = "https://hf-mirror.com"
# 添加依赖
(vippython) PS D:\OpenSource\Python\VipPython\information_extraction> uv add pandas
# 切换下目录,否则会报文件不存在
(vippython) PS D:\OpenSource\Python\VipPython> cd D:\OpenSource\Python\VipPython\information_extraction
(vippython) PS D:\OpenSource\Python\VipPython\information_extraction> uv run .\evaluate_model.py

evaluate_model.py

# 模型评估和测试
import json
import os
import torch
from transformers import AutoTokenizer, AutoModelForTokenClassification
from seqeval.metrics import classification_report, accuracy_score, f1_score, precision_score, recall_score
import pandas as pd


def evaluate_model(model_dir, test_file):
    """评估模型性能"""
    print("=" * 60)
    print("模型评估")
    print("=" * 60)

    # 1. 加载模型和tokenizer
    tokenizer = AutoTokenizer.from_pretrained(model_dir)
    model = AutoModelForTokenClassification.from_pretrained(model_dir)
    model.eval()

    # 2. 加载测试数据
    with open(test_file, 'r', encoding='utf-8') as f:
        test_data = json.load(f)

    # 3. 加载标签映射
    with open(os.path.join(model_dir, 'id2label.json'), 'r', encoding='utf-8') as f:
        id2label = json.load(f)
        id2label = {int(k): v for k, v in id2label.items()}

    label2id = {v: k for k, v in id2label.items()}

    # 4. 预测
    predictions = []
    references = []

    with torch.no_grad():
        for item in test_data[:50]:  # 测试前50个
            input_ids = torch.tensor(item['input_ids']).unsqueeze(0)
            attention_mask = torch.tensor(item['attention_mask']).unsqueeze(0)

            outputs = model(input_ids, attention_mask=attention_mask)
            preds = torch.argmax(outputs.logits, dim=2)

            # 转换预测
            pred_labels = [id2label[p.item()] for p in preds[0]]
            true_labels = [id2label[l] for l in item['labels'] if id2label[l] != 'O'][:len(pred_labels)]

            # 过滤特殊token
            pred_filtered = []
            true_filtered = []
            for p, l, attn in zip(pred_labels, item['labels'], attention_mask[0]):
                if attn == 1 and l != label2id['O']:
                    pred_filtered.append(p)
                    true_filtered.append(id2label[l])
                    break

            predictions.append(pred_filtered)
            references.append(true_filtered)

    # 5. 计算指标
    print("\n分类报告:")
    print(classification_report(references, predictions))

    print(f"准确率: {accuracy_score(references, predictions):.4f}")
    print(f"F1分数: {f1_score(references, predictions):.4f}")
    print(f"精确率: {precision_score(references, predictions):.4f}")
    print(f"召回率: {recall_score(references, predictions):.4f}")

    return predictions, references

if __name__ == "__main__":
    evaluate_model('./ecg_ner_model', 'data/out/bert_training_data.json')

image