Page MenuHomePhabricator

Add-a-Link — add two model features: `link_probability` and `context_w2v`
Closed, ResolvedPublic

Assigned To
Authored By
OKarakaya-WMF
Sep 8 2026, 8:17 AM
Referenced Files
F102411866: image.png
Sep 10 2026, 9:18 AM
F102411836: image.png
Sep 10 2026, 9:18 AM
F102410347: image.png
Sep 10 2026, 9:18 AM
Restricted File
Sep 9 2026, 9:15 AM
Restricted File
Sep 9 2026, 9:15 AM
F102209742: image.png
Sep 8 2026, 1:43 PM
F102209704: image.png
Sep 8 2026, 1:43 PM
F102209521: image.png
Sep 8 2026, 1:43 PM

Description

Feature 1 — link_probability (overlinking)

How often a phrase is a link when it appears at all:
linked_frequency / (anchor_frequency + linked_frequency), where
anchor_frequency = unlinked occurrences.
Common-knowledge terms ("education") appear mostly unlinked → low value → the flag for "should this be a link?".
Already computed in generate_anchor_dictionary.py, but only used as a hard filter (MIN_LINK_PROBABILITY) and then discarded.

Feature 2 — context_w2v (wrong-entity )

Existing w2v compares the whole article to the candidate target. It may be too coarse to
tell a painter from a musician of the same name. context_w2v compares against the
local context instead:

  1. Find the anchor's offset in the article.
  2. Take the N=5 nearest existing links (excluding the mention's own).
  3. Average their article_topics embeddings → local context vector.
  4. context_w2v = cosine(context vector, candidate-target embedding); 0.0 if no candidate embedding or no usable neighbor.

Experiment with the new features on the training set.
We will measure in the impact on accepted/rejected suggestions and reverted edits in the next tasks.
We use simple wiki during implementation and we run it on enwiki once we are ready.

Event Timeline

We have created a dataset for simplewiki with the new features and we share their values below:

context_w2v = we get higher context similarity when the label is 1. We expect this to help with the wrong entity problem e.g. an irrelevant person linked to a novel character.
link_probability = Link probabilities are higher when label is 1. We expect this to help with overlinking as common knowledge text/articles such as "education" may appear many times in articles without a link.

Both features seem to be spot-on.

We will get the same plots on the user decision dataset (accept/reject/revert) in the following task. T435831

image.png (1,469×1,225 px, 107 KB)

Simple wiki without the new features:
{F102260860, width=500}

Feature importance:

{'levenshtein': 0.36357102, 'freq': 0.23589364, 'ambig': 0.20608857, 'kurtosis': 0.078436226, 'w2v': 0.07389189, 'ngram': 0.04211869, 'wiki_db': 0.0}

Simple wiki with the new features:

{F102260879, width=500}

Feature importance:

{'levenshtein': 0.3609519, 'freq': 0.21732023, 'ambig': 0.1840521, 'kurtosis': 0.07332572, 'w2v': 0.06238799, 'link_probability': 0.061102565, 'context_w2v': 0.021081645, 'ngram': 0.019777866, 'wiki_db': 0.0}

Precision improved by 3.22% relative to the original value:
(0.833 − 0.807) / 0.807 ≈ 3.22%

Recall improved by 5.97% relative to the original value:
(0.408 − 0.385) / 0.385 ≈ 5.97%

link_probability and context_w2v

FeatureWhat it asksScope
link_probabilityIs this phrase usually a link, or usually plain text?Per anchor (same for every candidate)
context_w2vDoes this candidate fit the *nearby* links?Per candidate (homonyms differ)

w2v is cosine(page embedding, candidate). context_w2v is the same idea, but local.


link_probability

linked / (linked + unlinked)

link_probability is a global value for a phrase: one number per (wiki, anchor), counted over all articles in that wiki. It does not depend on the page you are currently linking.

linked = times the phrase is a wikilink. unlinked = times it appears as plain text (existing links stripped first). Near 1: editors almost always link it. Near 0: common prose, rarely a link (overlinking proxy).

This is the first model feature that uses unlinked occurrences. The others never see them: freq is how often this (anchor → title) pair is a wikilink; ambig / kurtosis only describe how those linked counts split across titles; ngram, w2v, levenshtein are string or embedding features. Unlinked counts were already computed to apply the hard MIN_LINK_PROBABILITY ≥ 0.065 filter, then dropped. Values above the threshold are now a model feature, so a phrase can have high freq and still score low if it is mostly plain text.

Article 1 — Physics

[[Albert Einstein]] developed the theory of relativity. Physics is a [[science]].

Article 2 — Biography

Albert Einstein later moved to the United States. He continued to work on science.

Article 3 — Relativity

The theory of relativity describes space and time. [[Albert Einstein]] published it in a science journal.

AnchorLinkedUnlinkedlink_probability
Albert EinsteinArt1, Art3 → 2Art2 → 12/(2+1) = 0.67
scienceArt1 → 1Art2, Art3 → 21/(1+2) = 0.33

On a real wiki, *Albert Einstein* is often > 0.8; *science* appears unlinked thousands of times and drops toward 0.


context_w2v

The general idea is to build a context vector from the existing links *near the mention*, so the model can focus on that part of the article instead of only the whole-page embedding. w2v is still the article-level similarity; context_w2v is local.

cosine( mean(N nearest existing-link embeddings), candidate embedding )

N = 5. Neighbors ranked by offset; the mention’s own link is excluded (shared content word). No usable neighbors → fall back to page-level w2v.

Toy embeddings: swimming = [0, 1], football = [1, 0].
cosine([0,1],[0,1]) = 1.0, cosine([0,1],[1,0]) = 0.0.

The wiki has two Jane Smiths: Jane Smith (swimmer) and Jane Smith (footballer). The mention Jane Smith is ambiguous; context_w2v uses nearby links to pick one.

Article — Sport in England

The [[Olympics]] champion Jane Smith won gold in [[swimming]].
...
...
Later, Jane Smith scored for [[Arsenal]] in the [[Premier League]].

Both mentions sit on the same page, so article-level w2v is identical. Local neighbors differ:

MentionNearest linksMeanSwimmerFootballer
first Jane SmithOlympics, swimming[0, 1]1.00.0
second Jane SmithArsenal, Premier League[1, 0]0.01.0

Same phrase, same article, different nearby links → different entity. link_probability is identical for both candidates; context_w2v is what disambiguates.

Note that these are toy examples. We will share real-world examples from the user-decision dataset soon.

Sharing the enwiki results: We get 4.8% improvement on precision and 8.5% improvement on recall.

  • without new features:
----------------------
   threshold     N  micro_precision  micro_recall wiki_db                       
0        0.5  5000              0.8      0.374206  enwiki
  • with new features:
----------------------
   threshold     N  micro_precision  micro_recall wiki_db                       
		0        0.5  5000         0.838649      0.406334  enwiki

image.png (858×135 px, 29 KB)

image.png (1,324×1,138 px, 139 KB)

image.png (1,344×1,150 px, 200 KB)

@kevinbazira merge request is ready for review.

Can you take a look when you have time?

https://gitlab.wikimedia.org/repos/machine-learning/ml-pipelines/-/merge_requests/93

Thank you for working on this @OKarakaya-WMF.

Had a look and it LGTM, approved!

I'm closing this ticket as we have achieved 4.8% improvement on precision and 8.5% improvement on recall in enwiki.

As a next step, we will focus on user decisions.
Afterwards, this work should be followed by productionizing the new model and releasing on the pilot wiki(s).