Skip to main content

opt-gamma

Optimized gamma agreement measure for two annotators, covering free segmentation, complex category labels and explicit relations between segments. Companion library of the paper An Optimized Gamma Agreement Measure.

Compared with the classical gamma of Mathet, Widlöcher and Métivier (2015), this variant uses a Jaccard positional dissimilarity (scale-invariant, interpretable as shared content), an explicit admissibility threshold with a soft orphan penalty, a relational coefficient for typed links between segments, and an exact Hungarian reduction for the two-annotator case. It is not a replacement for pygamma-agreement, which implements the classical n-annotator gamma, gamma-cat and gamma-k.

Install

pip install opt-gamma

Usage

from opt_gamma import (Span, Unit, Relation, GammaConfig,
                    gamma_segments, gamma_relations, gamma_composite)

# spans are half-open [start, end); use Span.from_inclusive for inclusive data
a = [Unit(Span(100, 150), "Claim"), Unit(Span(160, 210), "Example")]
b = [Unit(Span(102, 152), "Claim"), Unit(Span(162, 212), "Explanation")]

cfg = GammaConfig(alpha=0.5, tau=0.5, eta=0.5)
typ = gamma_segments(a, b, config=cfg)          # 0.7115 on this example

r1 = [Relation(Span(100, 150), Span(160, 210), "Illustration")]
r2 = [Relation(Span(102, 152), Span(162, 212), "Illustration")]
rel = gamma_relations(r1, r2, config=cfg)        # 0.9615

gamma_composite(typ, rel, lambda_typ=0.7)        # 0.7865

Per-category and per-relation-type diagnostics (the gamma-k idea, extended to relations):

from opt_gamma import gamma_k_segments, gamma_k_relations
gamma_k_segments(a, b, config=cfg)
gamma_k_relations(r1, r2, config=cfg)

Chance correction, with adaptive sampling:

from opt_gamma import CircularShiftNull, LiNonOverlapNull
cfg = GammaConfig(chance_correction=True, null_model=CircularShiftNull(),
                  n_iter="auto", seed=42)

Choices you have to make (and report)

Parameter Meaning Default
tau max Jaccard distance for a pair to be alignable (hard mode) 0.5
eta orphan penalty, in [0, 1]; must be > 0 0.5
admissibility "hard" (threshold) or "soft" (confidence weighting à la Mathet 2017) "hard"
on_no_admissible items with units on both sides but no alignable pair: "orphan_all" keeps them in corpus averages, "nan" excludes them and inflates the mean "orphan_all"
null_model CircularShiftNull (Mathet 2015, §5.2.1) or LiNonOverlapNull (Li et al. 2024) CircularShiftNull

The direction of the tau effect on corpus averages depends on on_no_admissible; see the paper. The Li null model is an exact uniform sampler over non-overlapping placements (their closed form assumes an additive measure, which an alignment-based disorder is not); the sampler and the analytical start distribution are both tested against exhaustive enumeration.

Corpus example

examples/french_argumentation.py runs the full pipeline of the paper's corpus study, with a CLI exposing every methodological switch.

Tests

python -m pytest

The suite pins the paper's worked example, edge cases (orphans, empty sides, aggregation policies, matrix validation) and the Li model against brute-force enumeration.

License

MIT. See CITATION.cff for how to cite.

Download files

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

Source Distribution

opt_gamma-0.4.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

opt_gamma-0.4.1-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file opt_gamma-0.4.1.tar.gz.

File metadata

  • Download URL: opt_gamma-0.4.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.11

File hashes

Hashes for opt_gamma-0.4.1.tar.gz
Algorithm Hash digest
SHA256 fe5c43a17fe7d85b22403d0cb86ee7d71822ebd71cb1637c5c1cc8391f87c933
MD5 96bfce1cc7295e55158ab1376720e2dc
BLAKE2b-256 5b894ae9ea6f5f578645ea66fabb241df611fd7812afeb56f7864a116f86c9b8

See more details on using hashes here.

File details

Details for the file opt_gamma-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: opt_gamma-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.11

File hashes

Hashes for opt_gamma-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78588d1e4b14c1a1f641cab6d9cf7fd48fbf2774fe54a3be2f311f44c54adbce
MD5 037a0093461cfd24f0ca6f8eca6106bf
BLAKE2b-256 5e964dd51417c0ab4c35af6cf4960151535ab1f1a7a6cc18985b0215d7984559

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page