Slashdot Mirror


Working Bayesian Mail Filter

zonker writes "A real, working honest to god Bayesian spam filter. I've been waiting for something like this for a while (since I first read Paul Graham's research paper on this very topic a few weeks ago). Well here's POPFile, a small but extremely effective Perl script that runs on just about any system Perl does. After just a little training was I able to get very effective filtering out of it. From what I understand the new email client that comes with OS X Jaguar has a feature similar to this, but I don't know if it is true Bayesian. Hopefully this kind of feature will become more prevalant in client software as I see the Google results for it are growing."

32 of 312 comments (clear)

  1. spambayes.sf.net by supton · · Score: 5, Informative

    Saw this a few weeks back... Spam filter in Python using Naive Bayes.

  2. Sure it's promising by bigberk · · Score: 4, Insightful

    And I'm going to check it out right now :) But one long standing I fear with such solutions is spammer's adapting to new environments (changing wording used, making the emails look more professional). Sure, they're dumb shits but they're still humans with brains.

    1. Re:Sure it's promising by outlier · · Score: 5, Informative

      While spammers will undoubtedly continue to refine the content of their messages, one of the strengths of using a Bayesian filter like this is that it uses the user's own spam and non-spam (ham) as the basis for its calculations. This means that messages are categorized not only by whether they contain spammy words, but also whether they contain the hammy words from your own messages. So, even if spammers could refrain from using words like "free" "mortgage" "sluts" and "spam", they probably wouldn't use words that discriminate your own ham from others (e.g., if you are a computer scientist, your mail may include hammy words like "algorithm" "compile" "project" or "stargate" that would help distinguish ham from spam. The challenge to the spammer would then be to target you with spam that looks like *your* ham (which is probably different from the ham of others).

      Future systems (assuming faster processors and more HD space) could include semantic analysis (e.g., Latent Semantic Analysis) to do an even better job and go beyond the word level.

    2. Re:Sure it's promising by rgmoore · · Score: 4, Informative

      Another important point is that there are some things that they can't hide, at least not in their current working model. If they're trying to sell you something, they have to describe what that thing is and where you can get it, and those descriptions are unlikely to be in any legitimate email. If they want to advertize a web site, they have to include its URL in the message, and the filter can catch that. If they advertize a physical address or phone number, the system can catch those, too. If they don't repeat the message, it means that there's inherently less spam, because I'm only seeing each add once.

      It's also not possible to disguise everything in their headers, so things like their posting host (either the one they pay for legitimately or any open relay they're taking advantage of) will wind up being a pointer to who they are. They certainly can't change anything about the headers that's added downstream of their posting host, so as long as they keep using the same one it's likely that there will be characteristic stamps there that the spammers absolutely can't change. I know that analysis of the headers is part of bogofilter, another Bayesian filter that I've been using to good effect.

      --

      There's no point in questioning authority if you aren't going to listen to the answers.

    3. Re:Sure it's promising by rgmoore · · Score: 4, Informative

      Bogofilter comes close to this. It has an operating mode where each file that it filters is automatically added to the appropriate corpus, either of spam or non-spam. Since it's correct the vast majority of the time, that means that there's very little for the user to do. When it is wrong, you just take the messages that it miscategorized and feed them back into the system with the notation that they were originally marked incorrectly, and it backs out the changes to the wrong category and adds them to the correct category.

      I'm using bogofilter with Evolution, and it works very well. I just have two extra folders, one for false negatives and one for false positives. When I notice mail that's been flagged incorrectly, I drag it into the appropriate folder and run a script that tells bogofilter to correct its mistake. Then I either flush the mail (if it was spam marked as non-spam) or process it normally (if it was non-spam marked as spam). I've only been using it for about two weeks and it already has a nearly zero false positive rate (i.e. incorrectly flagged as spam) and a usefully low false negative rate (i.e. incorrectly flagged as legitimate).

      --

      There's no point in questioning authority if you aren't going to listen to the answers.

    4. Re:Sure it's promising by tsg · · Score: 4, Insightful

      Any solution that requires spammers to be more clever is going to reduce the number of spammers. And that is the end goal.

      --
      People's desire to believe they are right is much stronger than their desire to be right.
    5. Re:Sure it's promising by Tim+Browse · · Score: 4, Interesting

      One interesting fact that came out of these statistical analyses of spam was from one that was featured a while back on slashdot - the guy was doing word analysis, and was looking for good spam indicators/correlations, and expected "sex" or "teens" to be a good match, but the best word was, surprisingly, "ff0000". This was because so much spam uses HTML mail with red text.

      So if nothing else, it will force spammers to stop using red text - that has to be some kind of victory :-)

      Tim

    6. Re:Sure it's promising by Alsee · · Score: 5, Funny

      (e.g., if you are a computer scientist, your mail may include hammy words like "algorithm" "compile" "project" or "stargate" that would help distinguish ham from spam.

      I have a cousin that lives in Nigeria and we regularly discuss tips on penis enlargement. He works at a bank refinancing mortgages and his wife is a professor at an accredited university. I work in in a Las Vegas casino producing shows featuring live nude showgirls. He offered to help me pay some bills and get out of debt (a generous offer, but I told him I just found a second part time job working from home earning thousands of dollars per week). My wife is a stock broker and I regularly let my cousin in on hot stock tips. I have an herb garden, I take viagra, and use rogaine. Since we both own the same brand of printer we've been working out the best way to refill the ink cartridges. I've been trying to lose weight, but it comes right back as soon as I quit smoking.

      I don't quite understand this "beysian filter" stuff, but I can't wait to try it out!

      -

      --
      - - You can't take something off the Internet! That's like trying to take pee out of a swimming pool.
  3. Mozilla in Process of adding Bayesian filter by AT · · Score: 5, Interesting

    The mozilla mail client is getting a Bayesian mail filter, too. See http://bugzilla.mozilla.org/show_bug.cgi?id=163188 . Unfortunately, it probably won't show up until after version 1.2 is released.

  4. That Google search... by Jugalator · · Score: 4, Insightful

    Try searching for "bayesian email filter" instead of just "bayes email filter" (as in the news post). You'll get better results and more hits since Google doesn't match "*bayes*" (as one would think) when searching for "bayes", but only the actual word "bayes".

    --
    Beware: In C++, your friends can see your privates!
  5. Bayesian? Wow!!! I'm sooo excited. (Irony!) by davids-world.com · · Score: 5, Interesting
    A true Bayesian filter, wow. Let's face it, statistical classifiers based von Bayes' formula are not really state of the art. They make false assumptions about the data (independence of features).

    More intelligent classification algorithms can solve non-linear problems far better. Check out Kernel Machines and, somewhat older, Maximum Entropy models.

    Enough nerd talk for today :-)

  6. Re:Whas that? by DalTech · · Score: 4, Informative

    Bayesian is statistical theory and methods useful in the solution of theoretical and applied problems in science, industry and government. http://www.bayesian.org/

  7. Forget Bayes by Evil+Adrian · · Score: 5, Funny

    We need the Stalin Mail Filter (TM) -- it detects spam, hunts down the spammer, and exiles them to Siberia.

    --
    evil adrian
  8. bogofilter by stype · · Score: 4, Informative

    This isn't exactly the first bayesian mail filter out there. I've been using ESR's bogofilter for weeks now, and I must say it works better than I could have ever imagined. Bogofilter however is simply for sorting out spam, while it appears this filter can sort out other things. But honestly, I can setup some simple filters to separate personal emails from work emails, so I'm not entirely sure the extra stuff is that useful.

    --
    -Stype
    Bus error -- driver executed.
  9. Re:Whas that? by Evil+Adrian · · Score: 5, Funny

    If you had just clicked the POPFile link, you would see the explanation.

    Initiative is your friend.

    Hyperlinks are your friend.

    Don't be afraid, just click.

    --
    evil adrian
  10. Re:Whas that? by dvk · · Score: 5, Informative
    From what I understand, it is a mail filter which determines what to filter out based on a statistics-based machine learning system called "Bayesian Learning".

    A couple of URLs quickly found on Google:
    http://www.faqs.org/faqs/ai-faq/neural-nets/part3/ section-7.html
    http://www.csse.monash.edu.au/courseware/cse5230/a ssets/images/week09.pdf

    Also, any decent AI/machine learning textbook ought to cover the topic.

    -DVK

    --
    "The right to figure things out for yourself is the only true freedom everyone shares. Go use it"-R.A.Heinlein
  11. Re:Server-side solutions? by cmeans · · Score: 4, Interesting
    James is a 100% Java Email server (SMTP, POP3, NNTP, and IMAP soon) that supports mail-server extensions via the Mailets API. I developed a Java implementation of the Bayesian rules discussed, so that they could be used in any configuration, but also provided a mailet wrapped implementation so that the filtering (or flagging) could be done at the server side.

  12. Re:Bayes Explained by johnynek · · Score: 5, Informative

    That's /. for you. You guys have modded up to 5 a post that is wrong in both of the equations it posts.

    It should be:

    Pr(h|D) = Pr(D|h) * Pr(h) / Pr(D)

    and:

    Pr("SPAM"|Email) = Pr(Email|"SPAM") * (proportion of spam) / (probability of getting this paticular Email)

    --
    jabber: johnynek@jabber.org
  13. SquirrelMail has a Bayesian plug-in by ptbarnett · · Score: 4, Informative
    Plugins - BayesSpam - Intelligent Spam Filter

    SquirrelMail is a WebMail client implemented in PHP. I use the client, but not the plugin (I use Razor).

  14. Professional Looking Spam May Be Impossible by Bob9113 · · Score: 4, Insightful

    This may be self-regulating. Consider the Skinner box; if something is capable of perfectly emulating recognition of Chinese, then it can be said to recognize Chinese. Likewise, if a spammer becomes sufficiently skilled at writing undetectable prose, he or she will have reached a skill level at which he or she can pursue more profitable writing ventures. The margins in spam are pretty small. Those spams are being written by morons because morons are cheap.

  15. Re:Server-side solutions? by koreth · · Score: 4, Interesting

    I've been using SpamProbe (which gets invoked from procmail) with excellent results.

  16. Re:I don't get any spam by moosesocks · · Score: 4, Funny

    Just post your email address, and we'll be happy to tell you.

    --
    -- If you try to fail and succeed, which have you done? - Uli's moose
  17. Re:Whas that? by sfe_software · · Score: 5, Informative

    If you had just clicked the POPFile link, you would see the explanation.

    I also highly recommend this link, as it goes into quite a lot of detail on this filtering technique. After reading it, I am going to give the Perl variation a shot.

    --
    NGWave - Fast Sound Editor for Windows
  18. Re:Bayes Explained by B'Trey · · Score: 4, Informative

    Read the referenced article. The only way to avoid the filter is to make your email sound like a normal message. In essence, the filter recognizes the sales pitch. If you remove the sales pitch to get your spam past the filter, you've removed the whole point of sending the spam.

    --

    "The legitimate powers of government extend only to such acts as are injurious to others." Thomas Jefferson.

  19. Where's the news? by Roadmaster · · Score: 4, Informative

    Just because it's the first one that actually makes the slashdot frontpage it doesn't mean it's the only one.

    Do a freshmeat search for bayespam, bogofilter and spamprobe, they're all working and quite mature bayesian filters (or should we say "paulgrahamian" in order to appease the "true bayesian" crowd). Hell, even a search for "bayes" will turn out a few more hits, like ifilter, which aims to automatically classify mail in different folders, but could be easily tuned to filter out spam.

    Of these, I think spamprobe is becoming the true "swiss army knife" of "bayesian" filtering; I did find both bogofilter and bayespam spartan, but they work well. spamprobe, on the other hand, is very actively maintained, is under constant improvement by the author, Brian Burton, and has given me excellent results getting rid of over 90% of my spam.

  20. Re:Is this intended for server, client, or both? by dzym · · Score: 4, Informative
    Yes, but remember, who runs the SMTP servers?

    The very design of the whole system specifies that anyone can just turn on a machine, hook it up to a network somewhere, and start spewing out messages to smtp ports all over the world.

    It doesn't have to be a sendmail, qmail, or exim server, remember. Some Windows viruses have taken advantage of that loophole to set up mini-SMTP servers in the network stack to continue propagating viruses without needing to connect to anything that provides authenticated external relay.

  21. Missing the point? by crisco · · Score: 5, Informative
    I think lots of people here are missing the point of POPFile. Everyone is happy to point out that there are already several assorted solutions to Bayesian mail filtering in many different languages. Nearly all of these work on the mail server. Now lots of us are qualified and interested in setting up our own mail server, customizing the mail processing our own One True Way and happily enjoying an inbox free of spam. But the average windows user has no idea how to set up a mail server. Others could easily do it but feel their time is better spent on other things, not admining a mail server.

    This is what POPFile is for. Its a pop3 proxy server, it sits between your pop3 client and the server and simply adds a classification to the headers (or the subject line for braindead mail clients).

    Currently POPFile is a bit rough on computer newbies, it needs a Perl install and such. However, if you read the forums it is intended to end up as an easily installed executable for windows users and to remain a nifty little perl script for the rest of the platforms where it might come in handy. So when those pesky friends and relatives come asking about all the viagra and farmyard spam they get (and you haven't already set them up on your tightly filtered mail server) set up POPFile for them.

    Also, its not just for spam filtering. Think of what you could do if you could go beyond simple rules for your inbox. Want email you think is important forwarded to your phone? Create a category for important email and go through your archives and feed POPFile email you would have wanted forwarded instantly. Create a new folder to recieve those mails and watch it for a few days, retraining POPFile until it is getting reasonably good at putting important mail in there. Now set up your mail system to forward those to your phone. Will it work? I don't know, but based on the results I'm getting, it probably would. How about using it to filter help desk emails?

    --

    Bleh!

  22. Re:Bayes Explained by Jim+Nugent · · Score: 4, Informative

    To put this in simpler terms, consider this scenario, 90% of all all X-rays that have a certain feature are from women with breast cancer. That is an easy statistic to compute; you have the x-rays and you follow up with the patients.

    The trick is derive a statement like: "If an x-ray has this feature, the patient has NN % chances of having breast cancer. THAT's useful tor screening, but it doesn't follow from the first statment (without some serious statistical calculations).

    Bayes theorem has all sorts of applications in prediction. In the case of E-mail, we can greatly oversimply and say "We found that X% of E-mails with this subject line are Spam." "We conclude that an E-mail with this subject line has Y% odds of being spam." Note that these are two very different statements. If we can find Y for the second statement and set a threshold we're comfortable with, say, 95% then we can create a filter with 95% confidence of correctness; it may well be wrong 5% of the time.

    Other responses have done a good job with the math so I won't repeat it here.

  23. Bayes by John+Garvin · · Score: 5, Funny

    Now we can tell spammers: "All your Bayes are belong to us."

  24. this battle cannot be won by mboedick · · Score: 4, Insightful

    These technologies are interesting, but the problem of spam should be solved at the source. Why should we waste our time, money, CPU and drive space trying to outwit spam with clever software? As has been said before, if you filter spam at the inbox, a lot of resources have already been wasted by the time it arrives.

    Spam is anti-social behavior - a perversion of technology to make a quick buck. It's a cancer, and we should try to kill it. If you try to fight it any other way, you will constantly be playing catch-up, as the spammers have technology on their side too.

    1. Re:this battle cannot be won by shayne321 · · Score: 4, Insightful

      These technologies are interesting, but the problem of spam should be solved at the source.

      And how do you propose we solve the problem at its source? Make it illegal? They'll just find loopholes in the law and/or move to a country where it is legal. Hunt them down and murder their wife and kids in front of them then hang them from a tree? Satisfying though it may be, last I checked murder was illegal.

      Techniques like this CAN eventually solve the problem.. As others have pointed out, for someone to buy something from a spammer they have to READ the spam. If they send out 1 million spams and 500,000 read them and 20 of them buy something, they'll keep doing it. If they send out 1 million and only 500 people read it and 1 person buys something, they'll loose their source of income and have to find a new line of work.

      Also, for each obstacle we put in their way (checksum databases, open relay databases, filters, etc) it costs them more time, effort and therefore, money to send their crap - all for less income.

      Shayne

      --
      Today I didn't even have to use my AK; I got to say it was a good day -- Icecube
  25. Growing a spam filter -- a firsthand experience by devphil · · Score: 4, Interesting


    So, the graduate CS course I'm taking this quarter is Evolutionary Computing, which is all about the convoluted nonlinear multidimensional-search-space problems, and guess what our current homework is? That's right, taking statistics on spam data, and using genetic algorithms to evolve a working spam filter.

    Due to one typo and two thinkos in my fitness evaluation function, my algorithm evolves -- within only a few dozen generations -- a solution which looks like this:

    Ignore the actual contents of the message. 34% of the time, it's spam.

    And it's right.

    --
    You cannot apply a technological solution to a sociological problem. (Edwards' Law)