ccd0 / 4chan-x

Adds various features to anonymous imageboards.
https://www.4chan-x.net/
Other
956 stars 131 forks source link

Bayesian filtering #1829

Open Witiko opened 6 years ago

Witiko commented 6 years ago

Spam filters such as SpamAssassin employ Bayesian filtering to separate desired (i.e. “ham”) from undesired e-mail (i.e. “spam”). In the kind of setup I am familiar with, after the user has hand-annotated a sufficiently large amount of both spam and ham (typically hundreds of e-mail messages), the classifier starts automatically classifying new e-mail based on a probability estimation of word occurrence.

Was anything like this ever tried for image boards? Imagine the user marking threads as ham (like) and spam (dislike), and the extension highlighting / hiding (hard approach) or sorting threads (soft approach) according to how well they fit the board-specific ham / spam models. This would complement the regex-based filtering currently supported by 4chan-X.

I suppose text analysis alone would be less effective on boards without much text content, so the classification could be further improved by having the user run an image classifier locally or by using a public web service that extracts feature vectors from images and use these in addition to the text. Then again, analyzing just the OP text might give good enough results at a fraction of the complexity.

Witiko commented 6 years ago

An exchange at a DPT at /g/ leads me to the conclusion that it would be useful to provide Bayesian filtering both at the level of threads and posts, much like the current 4chan-X regex filters do. The import / export text format of the Bayesian models might use similar syntax the regex filters use, just the regex part would be replaced by a list of spam / ham post IDs.

Witiko commented 6 years ago

Also to clarify – this is not a feature request, but a request for comments. I am willing to implement the idea described in the opening post. The purpose of this thread is to discuss the idea and determine how useful it would be.

EDR-Hat commented 6 years ago

I'm not sure about the text classification, I don't know, depending upon implemention it might be better than regex: phrases that you filter out can appear in longer posts that you might have otherwise wanted to see, so if it does some sort of weighting of ham vs spam this could be very useful. I'd be very wary of false positives though, so having some way of testing whether a hypothetical post would pass, add in said post to ham or spam and some way of managing those weights would be essential.

The image classification would be difficult to do with just running on md5 hashes. Ideally you'd want to do a few things to images in order for this to be useful: Perceptual hash images: this would be amazing on its own to filter them, making reused images that are slightly edited (goldface etc) filterable with just a few filters and getting around the problem that an image with a single pixel difference requires a whole new hash to identify what it is. Shape matching: I'm not sure if this is possible but if you take a base outline/shape that's used in many low effort posts (say goldface, feels guy, pepe) and compare whether it's present in an image would help classify posts even more.

Witiko commented 6 years ago

I'd be very wary of false positives though, so having some way of testing whether a hypothetical post would pass, add in said post to ham or spam and some way of managing those weights would be essential.

What I'm thinking of is displaying the P(word | spam) posterior estimates as a word cloud, so that the user can visualize the model. Adjusting the model is a bit trickier, since I'd like the model to be represented by a set of ham / spam post IDs – if the user is free to adjust the model arbitrarily, it becomes difficult to import / export the model using simple text serialization. Then again, keeping the posteriors immutable and allowing the user to increase / decrease the weights of individual words might just work.

As a default, the extension would not hide spam, but either make it semi-transparent or color-code it, since there will occasionally be false positives. Unlike with the regex-based filters, this is out of the user's hand.

The image classification would be difficult to do with just running on md5 hashes. Ideally you'd want to do a few things to images in order for this to be useful: Perceptual hash images: this would be amazing on its own to filter them, making reused images that are slightly edited (goldface etc) filterable with just a few filters and getting around the problem that an image with a single pixel difference requires a whole new hash to identify what it is. Shape matching: I'm not sure if this is possible but if you take a base outline/shape that's used in many low effort posts (say goldface, feels guy, pepe) and compare whether it's present in an image would help classify posts even more.

Rather than using hand-made image descriptors, I was thinking of using a recurrent neural network. Originally, I thought we would need an external service for this, but apparently both the image loading and the model building can be done in browser (at a performance loss).