Entity linking for BERT-like models
- Make sure there is an available version of python specified in
pyproject.toml, for example installed using pyenv. - Install
uv:curl -LsSf https://astral.sh/uv/install.sh | sh - Run
uv sync --all-groupsto create a local environment with project dependencies specified inuv.lock - Add a spacy language model
uv run spacy download en_core_web_trf - Set up
pre-commithooks:uv run pre-commit install. - To run
pre-commitindependently fromgit commit, runuv run pre-commit run --all-files - To run tests run
pytest test
NB.
- To run python scripts prefix the command with
uv run, e.g.uv run python script.py - To git commit also
uv runprefix, e.g.uv run git commit -m "first commit"to make surepre-commithooks are used from the correct python environement.
Ground truth lives in data/ground_truth as {"text": ..., "ground_truth": [{"itext", "a", "b", "entity_id"}, ...]}. pelinker-link-files scores against it automatically
whenever the input carries a ground_truth block:
uv run pelinker-link-files -m models/pelinker.pubmedbert.run1 \
-o reports/gt_score.json data/ground_truth/sample.0.gt.json
The output JSON gains a ground_truth_score block:
- Detection —
precision/recall/f1over character spans, matched by overlap within a document. Unambiguous and comparable across model versions. - Entity accuracy — over matched spans only, and only where the ids are comparable.
Since the KB-out work the linker predicts minted cluster ids (
kb::C0007) while the gold file carries input KB ids (PEL.000032), son_id_comparablemay be 0 andentity_accuracynull. That means undefined, not zero — read the detection numbers.
Add --kb-validation for a kb_lemma_validation block: the rate at which a mention's
predicted entity agrees with the entity its own lemma resolves to in the KB. That is a
distant-supervision consistency check, not end-task accuracy.
Programmatic entry points: pelinker.ground_truth.score_predictions_against_ground_truth
and pelinker.linker_kb_lemma.aggregate_kb_lemma_validation.
"Train" a model on a corpus
uv run python run/save_model.py
poetry run python run/serve
- Build image:
docker buildx build -t gg/pelinker:<current_version> --ssh default=$SSH_AUTH_SOCK . 2>&1 | tee build.log - Run container:
docker run --name pelinker --env THR_SCORE=0.5 gg/pelinker:latest