Autospam and Naive Bayes
pixelfed.blog
pixelfed.blog
As I pointed out in 2004[3], one technique around Naive Bayes (and other machine learning systems) was to pit machine learning against machine learning[4].
[2] https://en.wikipedia.org/wiki/POPFile
[3] https://blog.jgc.org/2023/07/how-to-beat-adaptivebayesian-sp...
[4] https://en.wikipedia.org/wiki/Adversarial_machine_learning
I think that's also my earliest encounter with the conception of "local web ui", while everything else at the time needs some this for configurations. It's also truly cross platform as it's written in perl.
One thing we saw that was more problematic is spams getting shorter and the use of image only spam. Turns out a lot of human to human communications is just short single sentence blurbs between people. We saw a lot of junk spam that didn't really have a call for action, but seemed to exist just for the purpose of making Bayes classification more difficult and error prone.
- accuracy generally a few points better than NB
- better generalisability due to the word embeddings acting as a bottleneck on expressiveness compared to NB or logistic regression which essentially model all words / bigrams as independent
- trained with cross-entropy, meaning that model scores can be used more effectively as a 'confidence' - e.g. for spam if you want to say something like "if prediction score > X, then filter", Naive Bayes is not ideal due to the 'naive' assumption which makes the scores very un-calibrated (it tends to give extremely high or low confidence scores, which gets worse with document length).
- is completely linear (or at least log-linear like NB), so explainability is super simple.
disclaimer: I haven't really thought about NLP for about 3 years so there may be something better than this now
Even better, however, is if you maximize the margin, so a large margin discriminative classifier should be your baseline. I believe that the classification layer in fasttext is equivalent to logistic regression (but not large-margin).
All that said, I would probably use vowpalwabbit as a baseline as it doesn't use word vectors underneath, is extremely fast and easy to use, and has many optimization option. This way you can determine if word vectors help your particular problem or not.
The insight of fasttext is to notice that these high dimension, unit vector word embeddings aren't an ideal way to learn - since they are orthogonal, during training time, a datapoint giving signal between the "spam" word vector and the label gives you no information about "spammer", or indeed any other word. Explicitly modelling and learning word vectors helps with this as now these are two points in a vector space that can be moved relative to one another.
[1] this remains true for LR if you rescale the vectors using e.g. TFIDF or use the hashing trick (a la vowpalwabbit).
That said, in reviewing the fastext bag of tricks paper on their classification module I’m now second guessing my assumption that they use complex embeddings. Their architecture is otherwise exactly reproducible in vowpalwabbit, and in fact in the paper they claim that it is equivalent to a specific combination of vowpalwabbit flags.
In particular the vowpalwabbit neural network flag is needed. However, vowpalwabbit only uses one hot vectors for their ngram features. The neural network flag just adds a hidden layer.
I had assumed that fasttext uses rich word embeddings in its classifier because it has another module to train them.
If it is actually the same as vowpalwabbit, then I can say that I’ve never had the extra hidden layer really help, though as they note it does make vowpalwabbit quite slow.
[1] https://orange3.readthedocs.io/projects/orange-visual-progra...
IMO logistic regression, or better fasttext (rank-limited logistic regression) should be the "default" baseline models you should use for NLP classification. They are trained with cross-entropy loss, so the scores are generally fairly well calibrated to an actual confidence score. Moreover since everything is linear (or at least logit-linear), you can do all the same explainability tricks as with NB (a little more effort for fasttext, but it is doable).
They solve this in the RF world by licensing who gets to broadcast. The only spammers on newspapers, radio, tv, post, satellite are people with a lot of cash.
ActivityPub, however, requires all POST requests to be signed by the server that sends them. The signature is made with an RSA key of the actor that performed the activity. The public key of that pair is inside the JSON object of the actor. So, to verify the signature for an incoming activity, you'd make a request back to the originating server to fetch the actor object. This makes spoofing impossible and domain bans practical.
It's still competitive with cutting edge approaches if carefully applied, and usually much faster so it can be applied to big data.
It's the engine behind Splink, the free Python library that I develop: https://github.com/moj-analytical-services/splink
Congrats on winning all those awards.
Fastlink was the inspiration for Splink - the fundamental statistical model is very similar. The first version of Splink was essentially a port to make it work faster and at greater scale, but we've subsequently added quite a bit of additional functionality
Feel free to ask questions if you run into any issues - we're usually fairly good at responding: https://github.com/moj-analytical-services/splink/discussion...
Thanks for this! I implemented Entity Resolution from scratch 2 years back and was mostly able to do deterministic linkages using identifiers or using TF-IDF on names as a suggestion for human intervention. Will be writing about my learnings in upcoming months [1].
Was mostly looking at research papers before but will take a look at your project - your documentation looks good!
[1] https://www.sheshbabu.com/posts/entity-resolution-challenges...
Back in 2004 I used to build spam filtering proxies using bayesian filters in spamassassin. And my experience in the fedi instantly made me realize they would be a quick and easy solution for a lot of fedi spam.
So it's fun to see pixelfed taking the leap. I can't wait to see how it evolves.
The fedi being very similar to e-mail is most likely going to see a lot of the developments of e-mail. For example domain verification would also be good. And I also predict some sort of reputation system for instance domains.
The URIBL addition really helped cut down junk, I wonder if it would help here too.
It's used to filter blog comments since over a decade now.
And I mean that with the surprise. It was tought to us as the simple method used before, and I was just testing whether it maybe can still be of use a bit. Mainly because it was easy to understand, it just counts, and I liked the position with the a priori probabilities. «Definitely still useful» was not the expected outcome.
Always love to see "simple" 20yo ideas find a new use case.
I wrote a spam filter, based on source addresses, "spammy" keywords and such, but it was about as effective as you would expect. Most spam had to be classified manually.
When I first read "A Plan For Spam", I sat down and wrote a Bayes classifier (pretty much a straightforward implementation of his proposal) in a couple of hours. Due to running my own server, I had a ready-made corpus of hand-curated spam and ham on which to train the classifier.
It worked astonishingly well, and I ran that classifier unmodified for another couple of years, until SpamAssassin became good.
Naive Bayes is the former, me thinks.
Naive Bayes is an application of Bayes Theorem to classification problems in machine learning. The problem it is solving is where you are trying to classify something and you have a fairly large number of features. The example that is frequently used in the ML community is imagine you have an image and you want to classify it as containing a cat (or not)[1]. The conditional probability you want is P(cat|pixels) or more specifically P(cat|p_1, p_2, ...., p_n) where p_i is a given pixel[2]. The problem is if you want to apply Bayes theorem you would want to calculate all those conditional probabilities and multiply them together. Since each conditional probability is small this would trend to zero in an actual floating point calculation and by the time you apply Bayes you would end up dividing by zero.
To work around this you make the "naive" (aka very obviously wrong) assumption that the probabilities P(cat|p_i) are independent. Then you get to just sum rather than multiply and the problem goes away. The Naive Bayes classifier turns out very useful in spite of the fact that this assumption is definitely wrong. The slightly different problem that arises that a few other people have mentioned is it means that since you are summing if your feature is say a word then as your text gets longer the score gets higher. So long ham emails would get classified as spam if you just used a threshold.
[1] The computer vision community seems weirdly obsessed with classifying cat photos
[2] in the spam filter case you're looking at P(spam|w_i) where W is a bag of words.
Our job was to take spam, identify who was sending it or, at a minimum, who it was advertising for and then forward that on to the law firms of the email providers.
This was right around the time that spam legislation was coming out so it was interesting to see how it was being applied directly to people we found.
I write a lot more detail about it here: https://twitter.com/alexpotato/status/1208948480867127296
But in the world of the future which is likely look at the "LLM of everything spoken/written" and given you can solve P(Y|X) P(X|Y) from a model that can do P(Y, X); LLMs could just win because of integration with everything.
Naive Bayes is an old spam filter that works on words independently from each other, ie not assuming any grammatical or semantical sense to what it processes.
It makes it simple, but efficient as a first line of defense against "dumb keyword stuffing spam".
(No LLM used, if that ever means anything these days).
It should be pointed out that a lot of ML models operate on a 'bag of words' approach where words (tokens) are considered without regard for structure/order. Bag of words is surprisingly powerful. It can be expanded to include n-grams (n words in order) and this makes it a powerful technique.
Punctuation (where punctuation is counted as a token) is a crazy powerful predictor in text classification including spam.