Evaluation library for span-level entity extraction
Project description
spaneval
Pure evaluation library for span-level entity extraction — takes ground truth and predicted (entity_type, start, end) tuples and returns precision, recall, and F1. Works with any pipeline that produces character-span predictions: LLM extractors, fine-tuned models, rule-based systems. Configurable overlap strategies, per-type precision/recall targets, and a scalar optimization score for automated prompt engineering.
Inspired by and a generalization of nervaluate.
Installation
pip install spaneval
Relationship to seqeval and nervaluate
seqeval works on IOB/BIO token sequences. LLMs output character spans — converting between the two is lossy and inconvenient.
nervaluate is the closest prior work and covers the SemEval 2013 strategies well. This library extends the same foundation with configurable overlap thresholds, per-type strategy assignment, and score() — a scalar optimization target for automated prompt engineering and hyperparameter search.
Quickstart
from spaneval import evaluate, to_entities
true = to_entities([
{"entity_type": "PERSON", "start": 0, "end": 10},
{"entity_type": "ORG", "start": 34, "end": 44},
])
pred = to_entities([
{"entity_type": "PERSON", "start": 0, "end": 9}, # slightly off boundary
{"entity_type": "ORG", "start": 34, "end": 44}, # exact
])
results = evaluate(true, pred)
results.report()
report() with no arguments shows a ± range across two strategies (Strict / AnyOverlap), giving an instant picture of how boundary precision affects your numbers.
For a guided walkthrough, see the examples:
examples/quickstart.py— five steps from zero-config to per-type strategy assignmentexamples/goals.py— two steps from goal definition to automated prompt optimization
Strategies
Two branches, covered in full in docs/:
Entity-count strategies score each entity as correct, incorrect, missed, or spurious:
| Strategy | Span | Type |
|---|---|---|
Strict |
Exact boundaries | Required |
Exact |
Exact boundaries | Ignored |
EntType |
Any overlap | Required |
Partial |
Any overlap; 0.5 credit if boundaries differ | Ignored |
ProportionalCoverage |
Fraction of true-entity characters covered | Ignored |
AnyOverlap |
Any overlap = full credit | Ignored |
Contains |
Prediction must fully contain the true span | Ignored |
MinimumOverlap |
Configurable threshold and overlap metric | Configurable |
TextCoverage counts characters rather than entities — useful when the goal is text redaction rather than entity classification.
Per-type strategies and goals
Different entity types can be evaluated under different strategies and held to different targets:
from spaneval.strategies import Strict, ProportionalCoverage
# different strictness per type
results.report(strategy={"PERSON": Strict(), "DATE": ProportionalCoverage()})
# precision/recall targets per type
from spaneval import Goal
goals = {
"PERSON": Goal(strategy=Strict(), recall=0.90, precision=0.80),
"DATE": Goal(strategy=ProportionalCoverage(), recall=0.80, precision=0.70),
}
results.report_goals(goals)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spaneval-0.2.0.tar.gz.
File metadata
- Download URL: spaneval-0.2.0.tar.gz
- Upload date:
- Size: 127.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f277b6a89b35ab3d39e21db319358f8340b0e87e752e820e860b8e859d09274
|
|
| MD5 |
642904d17c8e3a8fad9e8516d6d4b7d0
|
|
| BLAKE2b-256 |
b630ef92a935d5bd15e07a8a93d16b2ef7933aaa94a5b708bb0a220cd54be805
|
Provenance
The following attestation bundles were made for spaneval-0.2.0.tar.gz:
Publisher:
publish.yml on jamblejoe/spaneval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spaneval-0.2.0.tar.gz -
Subject digest:
4f277b6a89b35ab3d39e21db319358f8340b0e87e752e820e860b8e859d09274 - Sigstore transparency entry: 1194020491
- Sigstore integration time:
-
Permalink:
jamblejoe/spaneval@0997cff764bdf3d429138271f745954d44ab1343 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jamblejoe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0997cff764bdf3d429138271f745954d44ab1343 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spaneval-0.2.0-py3-none-any.whl.
File metadata
- Download URL: spaneval-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44292d1d221ef886fcf831ff83ef1fde53000bc54aa8aa012977a42eb929428b
|
|
| MD5 |
d0991cc9b64e12cf23e9cce9816c3169
|
|
| BLAKE2b-256 |
f91af5a049ceb3e4c839b25de95cec992e28f74eea445085aa018108f3a2d8df
|
Provenance
The following attestation bundles were made for spaneval-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on jamblejoe/spaneval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spaneval-0.2.0-py3-none-any.whl -
Subject digest:
44292d1d221ef886fcf831ff83ef1fde53000bc54aa8aa012977a42eb929428b - Sigstore transparency entry: 1194020588
- Sigstore integration time:
-
Permalink:
jamblejoe/spaneval@0997cff764bdf3d429138271f745954d44ab1343 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jamblejoe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0997cff764bdf3d429138271f745954d44ab1343 -
Trigger Event:
push
-
Statement type: