bibraeval.Comparator¶
- class bibraeval.Comparator(ground_truth, predictions, metric_schema=None, drop_mismatched_doc_ids=False)¶
Bases:
objectMatch two record collections and score their metadata fields.
The comparison matrix contains one row per document and metadata field. Document ID sets must match unless
drop_mismatched_doc_idsis enabled; in that case only IDs present in both collections are compared.Create a comparator for validated record collections.
- Parameters:
ground_truth (RecordCollection[TypeVar]) – Reference records keyed by document ID.
predictions (RecordCollection[TypeVar]) – Predicted records keyed by document ID.
metric_schema (FieldMetricMapping | dict[str, Any] | None) – Per-field metric configuration. Unlisted fields are omitted from scoring when a schema is supplied.
drop_mismatched_doc_ids (bool) – If true, compare only IDs in both collections; otherwise a mismatch raises
ValueError.
- compute_cell_agreement(comparison_matrix=None, metric=None)¶
Compute cell-level agreement between gold and predicted values.
With a metric_schema, only fields listed in the schema are scored, each with its configured metric and weight. Otherwise all fields are scored with metric (default Exact()) and weight 1.0.
- Parameters:
comparison_matrix (DataFrame | None) – Matrix to score; defaults to this comparator’s matrix. It must contain
field_name,gt_value, andpred_valuecolumns. Additional columns may be present to facilitate stratified analysis.metric (FieldMetric | None) – Metric used when no metric schema was supplied.
- Raises:
ValueError – If both
metricand a configured metric schema are supplied.- Return type:
DataFrame