-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/release prep #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
50ec357
Add basic binary option to metrics script
laurejt 47195b0
Update README
laurejt 8e0e102
Add project script for running compute_metrics
laurejt e6a6f65
Update uv.lock
laurejt 9952f82
Update unit tests
laurejt 30335a6
Adds option to save intermediate results
laurejt 40a9125
Update README.md
laurejt b101f0f
Add support for more general span relabeling
laurejt e2fcd48
Add defaults to alignment strategies
laurejt b3e3643
Update README per @rlkoeser's review
laurejt 839d011
Add pypi publishing github action
laurejt 46347ee
Update README.md
laurejt ec750b6
Per @rlskoeser's review
laurejt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # This workflow will upload a Python package using uv when a release is published | ||
| # Adapted from: https://docs.astral.sh/uv/guides/integration/github/#publishing-to-pypi | ||
|
|
||
| name: Upload Python Package | ||
|
|
||
| on: | ||
| # normal behavior: run when a new release is published | ||
| release: | ||
| types: [published] | ||
| # allow running manually on main (restriction within job) | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| # Cancel existing job(s) for workflow when a new one is queued | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| pypi-publish: | ||
| name: Upload release to PyPI | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: pypi | ||
| url: https://pypi.org/project/spanerr/ | ||
| permissions: | ||
| id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | ||
| contents: read | ||
| if: github.event_name == 'release' || github.ref_name == 'main' | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v.8.2.0 | ||
| with: | ||
| enable-cache: false | ||
| - name: Install Python 3.12 | ||
| run: uv python install 3.12 | ||
| - name: Build package | ||
| run: uv build | ||
| - name: Publish package | ||
| run: uv publish |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,101 @@ | ||
| # spanerr | ||
|
|
||
| `spanerr` is a Python library for evaluating span-level text annotations using customizable alignment and scoring strategies. | ||
| `spanerr` operates explicitly over span text boundaries (i.e., text indices) rather than over the annotated text itself. | ||
|
|
||
| Many span-level annotation tasks diverge significantly enough from named-entity recognition (e.g., long text spans, large label set) that the typical formulations for the evaluation metrics of precision, recall, and $F_1$ scores become insuitable. | ||
| `spanerr` addresses this issue by not only supporting customized scoring of (partial) span matches, but also customizing how the spans within document-level annotation sets are aligned for evaluation. | ||
| `spanerr` is designed for maximal flexibility generally leaving it to the user to determine what assumptions and restrictions are required in their use case. | ||
|
|
||
| [](https://github.com/Princeton-CDH/spanerr/actions/workflows/unit-tests.yml) | ||
| [](https://codecov.io/gh/Princeton-CDH/spanerr) | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ### Installation | ||
|
|
||
| Use pip to install as a Python package directly from GitHub. | ||
| Use a branch or tag name, e.g. `@develop` or `@0.1.0` if you need to install a specific version | ||
|
|
||
| ```sh | ||
| pip install git+https://github.com/Princeton-CDH/spanerr.git#egg=spanerr | ||
| ``` | ||
|
laurejt marked this conversation as resolved.
|
||
|
|
||
| ### Core Data Types | ||
|
|
||
| `spanerr` has three first-class objects: | ||
|
|
||
| - `Span`: An individual span annotation. | ||
| - `DocSpans`: A set of span annotations for a document. | ||
| - `SpanAlignment`: A set of aligned span annotations (reference, system) within a single document. | ||
|
|
||
| All three of these data types are immutable, but `SpanAlignment` does not currently support hashing. | ||
|
|
||
| #### Binarization | ||
|
|
||
| `spanerr` provides functionality for "removing" span labels from `Span` and `DocSpans` by setting them to a default label (empty string). | ||
| For `DocSpans`, overlapping spans will be merged and optionally neighboring spans can be merged. | ||
|
|
||
| #### Loading from dictionaries | ||
|
|
||
| `Spans` can be loaded from dictionaries with the following fields: | ||
|
|
||
| - `start` (int): starting text index (inclusive) | ||
| - `end` (int): ending text index (exclusive) | ||
| - `label` (str): optional span label (defaults to empty string) | ||
|
laurejt marked this conversation as resolved.
|
||
|
|
||
| `DocSpans` can be loaded from dictionaries with the following fields: | ||
|
|
||
| - `doc_id` (str): optional document id (defaults to empty string) | ||
| - `spans` (list[dict]): list of spans (in dictionary form, see above) | ||
|
|
||
| ### Core Functionality | ||
|
|
||
| In `spanerr` there are two core components to evaluating span annotations: (1) how spans are aligned and (2) how aligned spans are scored. | ||
| `spanerr` is intentionally designed so that these two components can be heavily customized. | ||
|
|
||
| #### Aligning span annotations | ||
|
|
||
| An alignment strategy is represented as a function that takes two sets of annotations (`DocSpans`) as input and returns an alignment (`SpanAlignment`) which will then be used for scoring. | ||
| There are little restrictions on the alignments themselves: the resulting `SpanAlignment` may contain transformed versions of the input `DocSpans` and no restrictions are made on its mapping between reference and system spans. | ||
| The idea is to allow for the creation of whatever alignment is useful for scoring. | ||
|
|
||
| The following alignment strategies are provided in `spanerr.align`: | ||
|
|
||
| - Select First : Select the first (sequential) matching system span for each reference span. | ||
| By default, spans match if they overlap and have the same label. | ||
| - Select Best : Select the best matching system span for each reference span. | ||
| By default, given spans that overlap and have the same label, the best match is the span pair with the highest jaccard similarity. | ||
| - Corppa : The alignment strategy used by [`corppa`](https://github.com/Princeton-CDH/corppa). | ||
| See `corppa`'s [evaluation documentation](https://github.com/Princeton-CDH/corppa/tree/main/src/corppa/poetry_detection/evaluation) for more detail. | ||
|
|
||
| For additional flexibility, alignment strategies may take additional inputs to further customize their behavior (e.g., use different span matching and span scoring strategies), but these will generally need to be set to a specific value (e.g., via a lambda function) before they can be used within `spanerr`'s evaluation workflow. | ||
| See the `spanerr.align.construct_aligner` for an example. | ||
|
|
||
| ### Scoring Aligmnents | ||
|
|
||
| Scoring an alignment (`SpanAlignment`) entails computing an alignment's *relevance score* (i.e., true positive, numerator for precision and recall). | ||
| So, a scoring strategy is represented as a function that takes an alignment (`SpanAlignment`) as input and returns its score (`float`). | ||
| This allows for both alignment-independent scoring strategies in which scoring depends solely on the individual scores of each reference-system span pair as well as those that don't. | ||
|
|
||
| Currently, `spanerr` provides the building blocks for constructing alignment-independent strategies using `spanerr.eval.relevance_score` and `spanerr.span_utils.composite_match_score`. | ||
| See `spanerr.compute_metrics.get_scorer` for an example of constructing scoring strategy functions. | ||
|
|
||
| ### Span Annotations File Format | ||
|
|
||
| A set of span annotations can be loaded into `spanerr` by providing a JSONL file with each line corresponding to a different document's annotations (i.e. `DocSpans`). | ||
| For examples see the files in `tests/test_data`. | ||
|
|
||
| ### Scripts | ||
|
|
||
| Installing `spanerr` currently provides access to the following command line script: | ||
|
|
||
| - `spanerr-metrics`: For calculating entity- or document-level aggregated precision, recall, and F-1 scores for given reference and system span annotation sets. | ||
| (Corresponds to `spanerr.compute_metrics.py`) | ||
|
|
||
| ## License | ||
|
|
||
| This project is licensed under the [Apache 2.0 License](LICENSE) | ||
|
|
||
| (c)2026 Trustees of Princeton University. | ||
| Permission granted for non-commercial distribution online under a standard Open Source license. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.