I'm currently building a fun script, that basically matches given phrases and gives a predefined response based on the match-points. You can ask it to retrieve some information based on live feeds, run tasks, tell anecdotes or just chat with her.

I already have built-in detection for badwords, caps lock or both. The program has a girl name and I tried to make as close to being a girly-girl as possible, on the logic terms (for example: everybody knows that most girly-girls take 700ms to respond to a question, joking of course). So here is a little example:

Client: #### you
Kiku: why are you being so mean to me :/

However, I really would like to add sarcasm-feature to it. So if you write something in sarcasm, then she will detect it and respond accordingly. Now this is a tricky part, How do you teach a script, what sarcasm is?

To me more specific. What are the most common sarcastic words used today? Or how to get that statistic? How can I make the script understand the context of the given phrase?


As this question is getting alot of hype, I think things should be cleared out a bit more. It is very clear, that making a script fully detect sarcasm is basically impossible. At least in reasonable matter. However, I do believe that some amount of possible sarcasm could be detected.

I currently have made it so far, that my script can detect a very limited sarcasm. I predefined some common sarcastic-words (however, alone they are useless.) For example: like, whatever, yeah, right and great. And then it first matches, the simple things, like uppercase and quoted: THANKS you are so smart or oh you are so "SMART".

Since the scripts main function is to do tasks or retrieve information, and afterwords it will ask if that was what you meant. Then I thought, adding "thanks" as a special variable. So yeah thanks or whatever thanks will trigger the possible sarcasm, and the script will ask you: "Do I detect sarcasm?" Your best bet would be to say "sorry" then, otherwise it will add a warning-point and if the limit is reached -- it will start ignoring you.

As these very very simple algorithms seem to actually work, then this idea has a future, of course after alot of tuning and tweaking. However, is somebody alot smarter would make a open-source software with the same idea in mind. Then this feature could be hooked to alot of functions on the web. Customer care would probably benefit the most, however, this kind of software could also be used detecting "flaggable"-content.

  • 14
    Until your script can actually understand what is being said (rather than picking up keywords), I think it's impossible to catch most sarcasm scenarios
    – Rob
    Commented Sep 11, 2011 at 23:34
  • 26
    @Kalle Let's be clear here. Sarcasm is one of the most subtle and advanced devices in spoken language. Even if you're a native English speaker, fully capable of picking up on the subtleties e.g. tone of voice and any relevant contextual information, you'll regularly fail to detect sarcasm. Non-native speakers stand almost no chance whatsoever. Take it to text and even the native speakers stand almost no chance. And you want computers, which struggle to dimly comprehend even the most simple of sentences, to solve this problem? Leave this to someone with a lifetime in speech and text analysis. Commented Sep 12, 2011 at 3:58
  • 17
    Make a script recognise sarcasm? That's reeeally useful ;)
    – zenzelezz
    Commented Sep 12, 2011 at 8:39
  • 12
    Come on - even Sheldon Cooper can't detect sarcasm...
    – Paul R
    Commented Sep 12, 2011 at 9:50
  • 3
    I don't think this question should've been closed, especially not as "not constructive". I'd cast a reopen vote right now if it weren't binding, but I think this question deserves a few reopen votes especially with the latest edit.
    – Adam Lear
    Commented Sep 12, 2011 at 20:15

6 Answers 6


If you had a full natural language processing system and a database of facts ala the IBM Watson system, you might be able flag some statements as possible sarcasm. For example, "I hear your mother has cancer and you just got fired!" "Yeah, isn't life wonderful!" could be flagged because it could recognize that getting cancer and loosing a job are not generally described as positive experiences.

I assume you don't have the resources to put together a Watson grade system. You could put together a database of commonly used sarcastic phrases, and then use some sort of text matching algorithm between the target statement and the sarcasm database. I have to guess that it won't be very effective because all the phrases that are used sarcastically are used sincerely more frequently. For example "That's a nice X." is usually used sincerely, but is sometimes used sarcastically.

Sarcasm is very closely related to deception. It's not uncommon for a person using sarcasm to deny it when challenged on it, and their choice of words makes denial possible. I suspect this means that a good sarcasm detector is probably about as hard a problem as a conversational program that passes the Turing test.

  • 1
    Thanks for your answer. This answers quality is definitely better then the one above. I think creating a database of actual phrase is gonna get too big. However a database of words + some other methods, could actually make it work (not 100%, but then again not 0%). I'm planning to add a verification step. If the script detects a slight level of sarcasm, it will ask: Was that sarcasm? If you respond: "OH NO", then it confirm the sarcasm and actually get mad and ignore you for some time (the time will be determined by the level of sarcasm). Commented Sep 12, 2011 at 1:24
  • 3
    I really think you want to stick with the phrases because sarcasm is all about context, and there are at least a few phrases that are more likely to be used sarcasticaly. "Yeah" isn't sarcastic, "Right" isn't sarcastic, but "Yeah, right!" is probably used more often sarcastically then sincerely. Commented Sep 12, 2011 at 1:56
  • 6
    As for the quality of the answers here, I have to say this is partially your responsibility. Natural language processing is a well known field that could provide you with several useful techniques, but you give no indication of having done any research to look up existing methods. It's a tough problem, and not something that can be usefully be answered in general in a SO post. Many, many, books have been filled on the topic of natural language processing. Commented Sep 12, 2011 at 2:07


if(string.Contains("<Sarcasm>")) containsSarcasm = true;


Honestly, I have no idea how to go about this. I think only about 30% of people in real life "get" sarcasm in the first place, so making a computer recognize it and understand it sounds like a very difficult task.

Edit Based on the comments to my original post, I believe that I have perfectly illustrated the extreme difficulty of the task that is being asked. Yes, the first half of my post was sarcastic. I even emphasized that fact by using a made-up markup tag. By posting a sarcastic comment about a trivial solution to an exceptionally difficult problem, and that sarcasm being interpreted as "unhelpful" brings up this question:

If you can't recognize written sarcasm, then how are you going to write an algorithm that recognizes it?

Oh, and Anna if someone includes the term "I think..." in their sentence, it usually indicates that it is an opinion that is being stated, not necessarily researched hard fact.

  • 3
    -1 I'm sorry, I'm not sure why this answer is getting upvotes. The code provided is 100% irrelevant to the question at hand and the the second part of the answer your are saying "i have no idea". Your answer is 30% on-topic and doesn't really help or give any good direction. Commented Sep 11, 2011 at 23:59
  • 18
    It's getting upvoted because the poster has pointed out that there's no practical way to do this. Since humans often can't detect sarcasm, then there's no way you can teach a machine to. Also, sarcasm is often conveyed by tone of voice, and hence often misunderstood in online communication.
    – Andy Waite
    Commented Sep 12, 2011 at 0:03
  • 1
    @Andy Waite Yes of course, you are correct. As I said hes answer is 30% on-topic (even-thought he started getting upvotes when there was no additional-text.) Still, I wont accept that answer, because.. yes of course you cannot get 100% match.. But even a 50% match? This answer is basically saying, "I don't understand your question, I think its not possible, Sounds hard, Just quit!" I mostly only get these types of answers in Programmers, next to "Why are you doing this? Use a framework!".. Commented Sep 12, 2011 at 0:12
  • 4
    @Kalle I agree with you. This answer is part sarcasm, part "I don't know", and part guesswork (30%? Really? Can you back that up?). It's entirely unhelpful and should've at best been a comment.
    – Adam Lear
    Commented Sep 12, 2011 at 0:34
  • 3
    Interesting comment thread - apparently even humans can't detect sarcasm (or lack thereof) reliably. Commented Sep 12, 2011 at 8:36

The problem of sarcasm detection is an open problem in computational linguistics - you'd be better served by searching google scholar than stackexchange for such things. There has, however, been some progress made on the issue. For spoken sarcasm, a robust recognizer can be built using "spectral and contextual features" that (the authors claim) detects sarcasm as well as a human annotator. The authors of the paper claim that the raw text is therefore not enough to detect sarcasm - indeed, they got better results by ignoring the actual words being said.

Tsur et al. have also reported some interesting results in textual sarcasm detection just last year with their SASI algorithm. They also report some additional followup findings in another paper.

In any case, this is the cutting edge of computational language research; do not expect anyone to hand you a libsarcasm on a silver platter. You will need large training datasets and a lot of free time to tweak your sarcasm detector - and even then, a precision of 77% (as reported in the SASI paper) isn't enough to reject a post based solely on a sarcasm flag.

  • Hmm, 77%? That seems to be better than most people. (no sarcasm intended) Commented Sep 12, 2011 at 8:38
  • @Piskvor, quite possibly, but I don't have statistics on that. It's better precision than the audio one at least.
    – bdonlan
    Commented Sep 12, 2011 at 15:06

I don't think this answer is a very realistic method of approach, but if you had the resources to do it I believe it would be possible. Consider google's reCaptcha project which uses human beings to decipher words that computers can not read ("Learn More Recaptcha Page"). I believe the problem is similar, in that you are trying to get a machine to figure out something humans are at least better at doing already.

Imagine you had the resources to ask millions of people to identify sarcasm to you within a typed conversation context. Imagine that you could ask that many people to submit to you the exact moment in the conversation when sarcasm was realized and as little of the conversation prior to the realization that one would need to mark that identification. This could be stored in a database let's say, which your program had access to. Then, as the user was typing the conversation to you, the database could be filtered for "similar" conversations.

How to evaluate similarity is something to think about, but one that I believe there's probably research in existence for already. I believe it would be very much like the theory behind spelling error corrections. Either way it would probably come down to a probabilistic value that the conversation being typed is in fact sarcastic, and at some point a threshold would have to be provided.

I do also like your idea of presenting the question "Was that sarcasm?" to the user and then using their response to reach a more accurate decision.

I do hope my answer was not a complete waste and I wish you luck in this endeavor.



Sarcasm detection in computational linguistics (aka natural language processing) is an extremely difficult problem in its own right. It is basically a classification problem where a model must be trained first. A similar problem for finding double-entendres (PDF file) was recently researched and published. The techniques for both problems are comparable.


My 2 cents:

Ask a psychologist about how to recognize sarcasm in phrases, with that info compare them to the input.

But it would be a really hard project, with the effort used in that, you could do the best O.S. in the world for sure :P

Not the answer you're looking for? Browse other questions tagged or ask your own question.