pelinker.linker_kb_lemma¶
Lemma-based KB training-entity index (same resolution as embedding-time matching).
KbLemmaValidationMetrics
dataclass
¶
Aggregate of the per-row lemma_kb_matches_predicted_entity flag.
This is the closest thing the pipeline has to a task-level accuracy: it asks whether the entity a mention was linked to is the same one its own lemma resolves to in the KB. The flag was already computed per row and attached to debug output, but nothing ever aggregated it, so no run produced a single number for linking quality — only intrinsic clustering scores (DBCV/ARI).
It is a weak, distant-supervision signal, not ground truth: it can only score rows
whose lemma resolves to a KB entity at all (:attr:n_resolvable), and it rewards
agreement with the same lemma matching that produced the training mentions. Read
:attr:match_rate as "does linking stay consistent with the KB dictionary", not as
end-task accuracy.
Source code in pelinker/linker_kb_lemma.py
match_rate
property
¶
Matches over resolvable rows; None when nothing was resolvable.
n_predicted
instance-attribute
¶
Rows that received an entity prediction at all.
n_resolvable
instance-attribute
¶
Rows whose lemma resolved to some KB entity — the denominator of :attr:match_rate.
resolvable_rate
property
¶
Share of rows the metric can say anything about at all.
aggregate_kb_lemma_validation(rows)
¶
Summarize rows already enriched by :func:enrich_entity_predictions_kb_validation.
Rows lacking the enrichment fields count toward n_rows but not n_resolvable,
so mixing enriched and unenriched rows lowers the resolvable rate rather than
silently inflating the match rate.
Source code in pelinker/linker_kb_lemma.py
build_kb_lemma_index(labels_map, nlp)
¶
Build {word_grouping: {lemma_string: kb_training_entity_label}} from labels_map values.
Mirrors the per-property lemma matching used at training time in
:func:pelinker.util.extract_and_embed_mentions (_wg_for_property for the bucket,
lemma strings for comparison), inverted to an O(1) lookup keyed by mention lemma.
Source code in pelinker/linker_kb_lemma.py
enrich_entity_predictions_kb_validation(rows, kb_lemma_by_wg, labels_map)
¶
Add validation-only fields to each prediction row (mutates rows in place).
Source code in pelinker/linker_kb_lemma.py
lookup_kb_training_entity_label(word_grouping, lemma, kb_lemma_by_wg)
¶
Resolve training entity label string from mention word_grouping + space-joined lemmas.