pelinker.ground_truth¶
Span-level scoring against the char-offset ground truth.
data/ground_truth/*.gt.json carries {"text": ..., "ground_truth": [{"itext", "a",
"b", "entity_id"}, ...]}. pelinker-link-files has always parsed it and echoed it
into the output, but nothing ever scored against it — the README pointed at
run/testing/run_pel_test.py "to obtain the accuracy of the model", and that script
does not exist. So the repo had no task-level number at all, only intrinsic clustering
metrics (DBCV/ARI).
Two levels are reported, deliberately separated¶
Detection — did the linker find the span? Precision/recall/F1 over character spans, matched within a document. This is unambiguous and comparable across model versions.
Entity agreement — of the spans it found, did it assign the right id? This one needs
care. Since the KB-out work, entity_id_predicted is a minted cluster id
(kb::C0007), while the ground truth carries input KB ids (PEL.000032,
RO.0002206). Comparing them directly scores zero for reasons that have nothing to do
with quality. Pass predicted_id_to_kb_in to translate, and read
:attr:GroundTruthScore.n_id_comparable before trusting
:attr:GroundTruthScore.entity_accuracy — when it is 0, the ids were never comparable
and the metric is undefined rather than bad.
GroundTruthScore
dataclass
¶
Detection quality, and entity accuracy over the spans that were detected.
Source code in pelinker/ground_truth.py
entity_accuracy
property
¶
Correct ids over comparable matched pairs; None when nothing is comparable.
n_id_comparable
instance-attribute
¶
Matched pairs where both sides carried an id that could be compared.
Zero means entity accuracy is undefined, not zero — most often because the model
emits minted KB-out ids and no predicted_id_to_kb_in map was supplied.
GtSpan
dataclass
¶
One ground-truth annotation: a character range in a document, plus its KB id.
Source code in pelinker/ground_truth.py
load_ground_truth_spans(path)
¶
Read *.gt.json (single object or list of objects) into spans.
Source code in pelinker/ground_truth.py
score_predictions_against_ground_truth(predictions, gold, *, match_mode='overlap', predicted_id_to_kb_in=None)
¶
Greedy one-to-one span matching within each document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
Sequence[Mapping[str, Any]]
|
Rows with |
required |
match_mode
|
str
|
|
'overlap'
|
predicted_id_to_kb_in
|
Mapping[str, str] | None
|
Maps |
None
|
Matching is greedy in document order, and each gold span is consumed at most once, so duplicate predictions over one annotation count as false positives rather than inflating recall.
Source code in pelinker/ground_truth.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |