Page MenuHomePhabricator

Dice coff/Levenshtein and hamming distance for page titles in Abuse Filter
Open, Needs TriagePublic

Description

Hi, for a long time an LTA is creating pages on enwn with the title visually similar to "This is a problematic string".
The create pages like "thís is a problemat1c string", "tnis iss a problemátiç strimg" and of such sorts. There is not much in the article body.

I really think dice coffecient, or some sort of string similarity algorithm, and then a hamming disctance calculating function for the page title can help preventing abuse.

Can these functions be added to Abuse Filter?

Related: T36912.

Event Timeline

Hi, why was this task created, given the previous discussion in T36912: Add string distance function to AbuseFilter?

@Aklapper @Tgr told me to create a task. Besides, this task specifically requests the functions only for page title.

It would be better to keep discussing string distance functions in one place.

Dice coefficient OTOH can be calculated relatively quickly (n*logn) so it should not have performance issues. It might not be terribly useful for long text, but maybe it would work for titles.

If someone decides to implement these (either Dice-Sørensen coefficient, or Levenstein distance, or something else) and is in need of some test cases, I have an idea for that: on Persian Wikipedia, we reglurly create redirects to articles where the redirect is only different in the use of certain characters. Specifically, the Persian standard keyboard uses ی yet non-standard keyboards may use the Arabic ي instead, and same goes for standard ک and non-standard ك so for a page with title یاک (مجارستان) you will also find a redirect titled ياك (مجارستان) created. If one runs edit distance or string similarity algorithms on fawiki article titles and main namespace redirects, they should be able to find those redirects quickly. One could even calculate performance metrics (sensitivity and specificity) for the implementation of the algorithm by assessing how many of the redirects it found, and how many other titles/redirects did it find and score highly that were not a correct redirect.

This should be implemented as a function, i.e.:

dist("hello", "world")

Some abuse filters would need to check if two revisions of a page are closely related, such as to find canned edit summaries. See https://en.wikipedia.org/wiki/Wikipedia:Edit_filter/Requested#Significance-misleading_edits.

For example, say we have three strings:

  1. a: Among incarcerated youths recieving remedial education during their incarceration, 43% do not return to school. 40% re-enroll, but drop out within a year. 10% drop out after re-enrolling, but after more than a year. Only 7% graduate high school successfully.
  2. b: Among detained youths recieving remedial education during their detention, 43% do not return to school. 40% re-enroll, but drop out within a year. 10% drop out after more than a year. Only 7% graduate high school successfully.
  3. c: 43% of detained youths recieving remedial education do not return to school. 40% re-enroll, but drop out within a year. 10% drop out after more than a year. Only 7% graduate high school successfully.
dist(a, b)
    25
dist(a, c)
    59
dist(b, c)
    49

Just to clarify, I think there's agreement on the fact that this would have to be a function, and that it would be better to mention the algorithm used. However, as I wrote in T390508#10692270, the main concern is that string distance can be computationally intensive. We cannot expose a levenshtein function and have people freely run it on, say, the old and new wikitext of a page.

Just to clarify, I think there's agreement on the fact that this would have to be a function, and that it would be better to mention the algorithm used. However, as I wrote in T390508#10692270, the main concern is that string distance can be computationally intensive. We cannot expose a levenshtein function and have people freely run it on, say, the old and new wikitext of a page.

So will it be less problematic if we can only get the distance between the old and new wikitext of a page (i.e. implementing this feature as a variable)?

distance

That would still be an issue for larger pages. I ran a bunch of quick tests using a JS implementation and it can take several seconds to several minutes to simply compare two consecutive versions of some of our larger pages (I took some featured articles as examples). It is possibly that a PHP implementation running on Wikimedia cluster would be faster the running the JS implementation on my modern laptop, but even if it were to be 10 times faster, it would still be in the many seconds range which is not acceptable. Recall that AbuseFilters need to run completely before the page can be saved.

I am starting to think that while this feature may be desirable, its implementation should live with bots who check edits retrospectively, as opposed to within MediaWiki or its extensions.

Maybe we could calculate the distance variable as simply the edit distance between added_lines and removed_lines. This way, we'll only check changed parts, and not big blocks of text.

There are standard algorithms for bounded Levenshtein distance which are not expensive for a small bound. E.g. time cost of the Landau–Myers­–Schmidt variant scales linearly with the article length and the bound in the worst case. Of course that's to some extent offset by the performance drop of having to implement such an algorithm in userland, but even so might be worth it. Would be a lot of work though.