Skip to main content

Field-level confidence evaluator SDK for routed extraction results

Project description

routed-confidence

字段级置信度评估 SDK。

这个包只负责一件事:输入一条提取结果,输出每个字段的置信度分数。它不计算检出率、误伤率、日报统计,也不包含 Web、API 服务或自动迭代逻辑。

位置

源码目录:

routed_confidence/

主要入口:

routed_confidence/evaluator.py

内部评分组件:

routed_confidence/internal/confidence_evaluators/

默认规则文件:

routed_confidence/rules/meeting_ruler.json

安装

在当前仓库本地开发安装:

pip install -e .

从本地 wheel 安装:

python3 -m pip wheel . --no-deps --no-build-isolation -w dist
pip install dist/routed_confidence-0.1.0-py3-none-any.whl

如果发布到 PyPI 或私有 PyPI 后:

pip install routed-confidence

Python 导入名使用下划线:

from routed_confidence import ConfidenceEvaluator

使用

from routed_confidence import ConfidenceEvaluator

record = {
    "extraction_result": {
        "会议召开时间": {
            "value": "2026-05-20 14:00:00",
            "content": "会议召开时间为2026年5月20日14:00",
            "type": "text",
            "title_path": ["一、会议基本情况"],
        }
    },
    "input_text": "会议召开时间为2026年5月20日14:00。",
}

evaluator = ConfidenceEvaluator()
result = evaluator.evaluate(record)
print(result)

也可以使用一次性函数:

from routed_confidence import evaluate_confidence

result = evaluate_confidence(record)

返回格式

{
  "field_scores": {
    "会议召开时间": {
      "source_value": "2026-05-20 14:00:00",
      "total_score": 0.75,
      "dimension_scores": {
        "schema": 1.0,
        "similarity": 0.82,
        "historical": 0.5,
        "relation": 1.0
      },
      "reason": "字段符合规则要求",
      "violations": [],
      "suggestions": []
    }
  },
  "summary": {
    "total_fields": 1,
    "average_score": 0.75
  }
}

注意:SDK 不返回 is_correctis_correct 属于“标注数据 vs 提取数据”的评测逻辑,不属于置信度 SDK。

自定义规则和权重

from routed_confidence import ConfidenceEvaluator

evaluator = ConfidenceEvaluator(
    rules_file="/path/to/meeting_ruler.json",
    weights={
        "schema": 0.1,
        "sim": 0.2,
        "wilson": 0.1,
        "relation": 0.6,
    },
)

如果不传 rules_file,SDK 会优先寻找当前项目里的 schema/ruler/meeting_ruler.json,找不到时使用包内置的默认规则。

发布

安装构建工具:

pip install build twine

构建:

python -m build

会生成:

dist/routed_confidence-0.1.0-py3-none-any.whl
dist/routed_confidence-0.1.0.tar.gz

上传到 PyPI:

twine upload dist/*

上传到私有 PyPI:

twine upload --repository-url https://your-private-pypi/simple/ dist/*

发布后安装:

pip install routed-confidence

当前边界

  • 只做单条/字段级置信度评估。
  • 不计算检出率。
  • 不计算误伤率。
  • 不依赖 methods/apimethods/web_confmethods/reflect_rule
  • 不要求用户导入内部四维组件。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

routed_confidence-0.1.0.tar.gz (50.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

routed_confidence-0.1.0-py3-none-any.whl (63.8 kB view details)

Uploaded Python 3

File details

Details for the file routed_confidence-0.1.0.tar.gz.

File metadata

  • Download URL: routed_confidence-0.1.0.tar.gz
  • Upload date:
  • Size: 50.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for routed_confidence-0.1.0.tar.gz
Algorithm Hash digest
SHA256 655228a47ac9e96c0640830350880732842d5123aee8ee1f65ed2441872b045b
MD5 960ec5bada8f7f7feb31eaec466bd24c
BLAKE2b-256 9b9fd38ebf608c5f0186475c9bde8e36c466366f2ae3fc883028410f47f7e33c

See more details on using hashes here.

File details

Details for the file routed_confidence-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for routed_confidence-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d390818dbe1e1f5619314474310adeb6a4676b3e4794264b820f5d8d912eda44
MD5 2fd973313a9dd293b1808b343dc7d432
BLAKE2b-256 b7c9768ca660433cbdad0f49a4f4e0b3d1da1a2a627c06e67c24c184803d914f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page