Live data from Hacker News

Autospam and Naive Bayes

pixelfed.blog

21–30 of 39 posts

Re: Autospam and Naive Bayes

#21
Was working in NLP from about 2014-2020. At the start, NB was indeed generally the best performing baseline model you could use, and we would train it for every task. However, we came to realise that Facebook's FastText model[1] was almost always the better choice as soon as your training set was more than a few hundred samples. Some advantages:

- 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

[1] https://github.com/facebookresearch/fastText

Re: Autospam and Naive Bayes

#22
post #15

No mention of the spammers counter-attack,which was to stuff their spam with keywords to cause naive bayes to misclassify important emails as spam and cause it to be turned off due to unacceptable false positive rates. Spam-filtering is tough because it is an adversarial problem.

Its tough cause cost to broadcast is free on the internet.

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.

Re: Autospam and Naive Bayes

#24
Maybe a good place to ask why my Thunderbird spam filter seems broken? It used to work fine, then something happened (maybe I deleted the emails in Junk but that shouldn't affect the corpus). Now it doesn't seem to learn anything and I keep seeing the same Spam in the Inbox. This is with v102 on Win 10. Also with a few previous versions.

Re: Autospam and Naive Bayes

#25
Just as background for people who don't work with this stuff much, this is my understanding.

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.

Re: Autospam and Naive Bayes

#26

Was working in NLP from about 2014-2020. At the start, NB was indeed generally the best performing baseline model you could use, and we would train it for every task. However, we came to realise that Facebook's FastText model[1] was almost always the better choice as soon as your training set was more than a few hundred samples. Some advantages: - accuracy generally a few points better than NB - better generalisabili…

Theoretically, any discriminator that maximizes the expected value rather than the underlying distribution will be better. Logistic regression is an example of a discriminative classifier.

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.

Re: Autospam and Naive Bayes

#27
If folks are curious about what it was like fighting spam back in the early 2000s, I used to work at a firm that was contracted by some of the big email providers.

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

Re: Autospam and Naive Bayes

#28
post #26

Was working in NLP from about 2014-2020. At the start, NB was indeed generally the best performing baseline model you could use, and we would train it for every task. However, we came to realise that Facebook's FastText model[1] was almost always the better choice as soon as your training set was more than a few hundred samples. Some advantages: - accuracy generally a few points better than NB - better generalisabili…

Theoretically, any discriminator that maximizes the expected value rather than the underlying distribution will be better. Logistic regression is an example of a discriminative classifier. 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-margi…

All bag-of-words models use some kind of word vector - for a normal logistic regression / naive bayes, say "spam" and "spammer" are first and second indexed words in the vectorizer, then their word vectors are like [1, 0, 0, ....] and [0, 1, 0, ....] (length = vocab size). For both logistic regression and fasttext you get the 'document vector' by adding up their respective word vectors before applying a final linear projection + softmax to get the class predictions [1]

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).

Re: Autospam and Naive Bayes

#29
post #22
post #15

No mention of the spammers counter-attack,which was to stuff their spam with keywords to cause naive bayes to misclassify important emails as spam and cause it to be turned off due to unacceptable false positive rates. Spam-filtering is tough because it is an adversarial problem.

Its tough cause cost to broadcast is free on the internet. 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.

Fediverse is slightly better than email because there is a cost in the domain from which you send spam. Vanilla SMTP provides zero authentication so anyone can impersonate any domain. Technologies like DKIM and SPF are relatively new and not everyone uses them.

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.

Re: Autospam and Naive Bayes

#30

See also the Paul Graham classics "A Plan For Spam" (2002) [0] and "Better Bayesian Filtering" (2003) [1]. Always love to see "simple" 20yo ideas find a new use case. 0: http://www.paulgraham.com/spam.html 1: http://www.paulgraham.com/better.html

Back in the day, I ran my own email server, and dealing with spam was a constant pain in the butt.

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.

Post reply on HN