Page MenuHomePhabricator

Introduce case sensitivity to Add-a-Link
Closed, ResolvedPublic

Description

The machine learning model being used in Add-Link-Structured-Task often makes erroneous suggestions that appear to reflect a lack of knowledge of case sensitivity.

For example, @Rich_Farmbrough reports that Listen to the Music (an album) has been suggested over the phrase "listen to the music". In another example, Secondary school was suggested over the words in "Had his primary education at Nisuco Staff Children School Bacita and secondary education at Government Secondary School Bacita, Kwara State but obtained..." (something a newcomer subsequently did).

Changing-Benjamin-Justice-Soghie-Simple-English-Wikipedia-the-free-encyclopedia-07-23-2025_01_48_PM (2).png (1,172×388 px, 271 KB)

This task captures the work around training the machine learning model to make better suggestions in light of the signals case sensitivity provides.

Benefits:

  • This could reduce the error rate of the model, particularly around instances of partial name links, as in the second example above. (To frame it another way, a human seeing a phrase with the capitalization xxxxxxx xx Xxxxxxxx Yyyyyyyyy Yyyyyy Xxxxxx can probably figure out that suggesting a link over the Y-words is a bad idea because all four capitalized words probably form a single multi-word term. A properly trained machine learning model could hopefully do the same.)

Risks/concerns/challenges:

  • Sometimes articles have bad capitalization, and case sensitivity could lead the model to misjudge these instances. In particular, articles that are underdeveloped and have poor grammar are disproportionally likely to appear in "Add a Link" and are also disproportionally likely to have bad capitalization.
  • Article titles almost always begin with capitalization, which introduces a challenge when compiling the data to train the model with. One possible solution is to use the Wikidata item label linked to the article rather than the article title itself, since Wikidata items aren't supposed to capitalize item labels unless they're proper nouns (e.g. the English Wikipedia article "House" has the Wikidata item label "house"). However, some Wikidata item labels may be erroneously capitalized, introducing errors into the data.

This task was originally located at T405185, which has since been usurped to focus specifically on named entity recognition. It was split off again following this discussion.

Event Timeline

I suggest to implement it in the following way:
Related part from the analysis: https://phabricator.wikimedia.org/T435526#12240876

We looked into several features of the reverted suggestions (capitalization,
probability, location in the article, revert comments, etc.) to see whether
reverted add-a-link edits share a structure. One pattern stands out:

case-insensitive exact match, and
target is multiple words, and
every word in the target starts with a capital letter, and
at least one word in the text does not start with a capital letter.
Example edits:

https://en.wikipedia.org/w/index.php?&diff=prev&oldid=1360300286 ("so much fun")
https://en.wikipedia.org/w/index.php?&diff=prev&oldid=1359936045 ("an evening visit")
Accepted is 80.8% of all suggestions, rejected 19.1%, and reverted 1.7% of published
add-a-link edits. Normalizing to share of all suggestions:

Accepted (cost): 3.5% = 3,246 suggestions
Rejected (gain): 16.6% = 3,677 suggestions
Reverted (gain): 9.2% = 133 suggestions
Still worth doing as a quick win via T434259. Noting that it will fix similar cases to "listen to the music" but not the cases similar to the "secondary school".
We will still need NER ( T405185 ) for the similar cases.

Change #1330423 had a related patch set uploaded (by Ozge; author: Ozge):

[research/mwaddlink@main] addalink: Filter reverted-capitalization link suggestions

https://gerrit.wikimedia.org/r/1330423

Change #1330423 merged by jenkins-bot:

[research/mwaddlink@main] addalink: Filter reverted-capitalization link suggestions

https://gerrit.wikimedia.org/r/1330423

Change #1332676 had a related patch set uploaded (by Ozge; author: Ozge):

[operations/deployment-charts@master] linkrecommendation: Update image to 2026-08-28-113209-production

https://gerrit.wikimedia.org/r/1332676

Change #1332676 merged by jenkins-bot:

[operations/deployment-charts@master] linkrecommendation: Update image to 2026-08-28-113209-production

https://gerrit.wikimedia.org/r/1332676

Production is updated with the suggested change:

curl "https://linkrecommendation.discovery.wmnet:4005/v1/linkrecommendations/wikipedia/en/Ela-May_Demircan?threshold=0.5&max_recommendations=15" | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1137  100  1137    0     0    962      0  0:00:01  0:00:01 --:--:--   963
{
  "links": [
    {
      "context_after": " ",
      "context_before": " ",
      "link_index": 0,
      "link_target": "Soap opera",
      "link_text": "soap opera",
      "match_index": 0,
      "score": 0.7373344302177429,
      "wikitext_offset": 472
    },
    {
      "context_after": " I'm excit",
      "context_before": "s so much ",
      "link_index": 1,
      "link_target": "Fun (band)",
      "link_text": "fun.",
      "match_index": 0,
      "score": 0.6342705488204956,
      "wikitext_offset": 10091
    },
    {
      "context_after": "; in respo",
      "context_before": "played by ",
      "link_index": 2,
      "link_target": "Charlotte Riley",
      "link_text": "Charlotte Riley",
      "match_index": 0,
      "score": 0.8457676768302917,
      "wikitext_offset": 15512
    }
  ],
  "links_count": 3,
  "meta": {
    "application_version": "d1c9755",
    "dataset_checksums": {
      "anchors": "ab0a4c3fc5dcf9e6404c45eaad1eb463b38673a4936ab3f80e7dcdbf8130dee5",
      "model": "c25a9fb36577a272dd7ca101655d6169bf8a86dbfb1edce7c9b6ee445dec8e71",
      "pageids": "05391e1229aefc087c5076bea2042cddcc0d23bded0f6262cc474898a954c96e",
      "redirects": "56e8089b9d930b4ff77dbc9495c6a2e67c48d8d8a023f9b148e3bbfe5a98665f",
      "w2vfiltered": "59cb88563ca2e0d1992d71d28921f04e902880a9bc9d03081360cbef69fa229c"
    },
    "format_version": 1
  },
  "page_title": "Ela-May Demircan",
  "pageid": 77583807,
  "revid": 1372257852
}

previously we got "so much fun" suggestion:

{
     "context_after": ". I'm exci",
     "context_before": "of her is ",
     "link_index": 2,
     "link_target": "So Much Fun",
     "link_text": "so much fun",
     "match_index": 0,
     "score": 0.7048016786575317,
     "wikitext_offset": 10083
   },
Trizek-WMF subscribed.

For next Tech News:

The model used with Add a link has been upgraded. It offers improved detection of links with different capitalization. This change will help avoid some ambiguous suggestions caused by the presence or absence of capital letters in an article title, such as on cultural goods. A second phase of improvements [https://phabricator.wikimedia.org/T435526#12240876 is scheduled]. [https://phabricator.wikimedia.org/T434259]