37

I was asked to write an algorithm to detect sarcasm but I came across a flaw (or what seems like one) in the logic.

For example if a person says

A: I love Justin Beiber. Do you like him to?

B: Yeah. Sure. I absolutely love him.

Now this may be considered sarcasm or not and the only way to know seems to be to know if B is serious or not.

(I wasn't supposed to be in depth. We were given a bunch of phrases and just were told that if these were in the sentence then it was sarcastic but I got interested?)

Is there any way to work around this? Or are computers absolutely stuck when it comes to sarcasm?

(I suppose it depends on the tone of the speaker but my input is text)

Community
  • 1
  • 1
cjds
  • 8,268
  • 10
  • 49
  • 84
  • 8
    I think sarcasm is largely dependant on the tone of the speaker. Unless you knew B didn't like Justin Beiber their would be no way of knowing whether or not it was a sarcastic comment – bluestunt Dec 31 '12 at 04:23
  • 1
    A second, qualifying question to resolve ambiguity would work wonders, e.g. "what's your favorite song by Justin Bieber?"...the sarcastic soul (myself among them) couldn't name a single one. – Tim M. Dec 31 '12 at 04:23
  • 8
    I know this is of no help, but a lot of *people* have difficultly determining sarcasm in text! – ceyko Dec 31 '12 at 04:24
  • 2
    I think without having audible tone, this is damn-neared impossible. – Jonathon Reinhart Dec 31 '12 at 04:24
  • Are the sentences written by users ? or no ? Becuase if so there is few ways you could do it. – Sir Dec 31 '12 at 04:25
  • Yep sentences are written by users. Its a simulated conversation between 2 people – cjds Dec 31 '12 at 04:25
  • 4
    You might have more luck asking english.stackexchange.com to see if *humans* can detect sarcasm. – hafichuk Dec 31 '12 at 04:27
  • 6
    Oh, good luck with all *that*! – Bill the Lizard Dec 31 '12 at 04:31
  • what an awesome question /nosarcasm – Mudassir Hasan Dec 31 '12 at 04:40
  • 1
    I voted to close as Off-Topic. This question is more of a discussion, rather than a specific programming related. There are a lot of valuable comments and answers, but none is really a "right" solution. – Alan Dec 31 '12 at 04:42
  • I think the answers provided are more than extensive enough and covers the topic anyway. To sum it up its very likely to be impossible. – Sir Dec 31 '12 at 04:47
  • 6
    A scholarly article on sarcasm detection , algorithm called SASI - Semi-supervised Algorithm for Sarcasm Identification developed at Hebrew university . Detects with 77% accuracy ...http://www.aaai.org/ocs/index.php/ICWSM/ICWSM10/paper/viewFile/1495/1851 – Mudassir Hasan Dec 31 '12 at 04:48
  • 2
    Wow, Dr. Sheldon Cooper would love you dude! – Timothy Dec 31 '12 at 04:55
  • @m.hasan - great paper. I think the researcher's source material had a bit more context than arbitrary conversation, but it proves it definitely can be done. – Tim M. Dec 31 '12 at 04:59
  • Some of the best satiric writers keep their tongues firmly in cheek. For example, an unwary reader might read Swift's "Modest Proposal" as a straightforward (if bloodthirsty) pamphlet. Analysis of tone won't help you there. Good luck. – WaywiserTundish Dec 31 '12 at 07:37
  • Try the input: `this is not an input` :) – S.D. Dec 31 '12 at 08:01
  • 2
    You'll have to wait. The Germans are still working on a humor-detector. – wildplasser Dec 31 '12 at 09:35
  • And, here is a recently added [video talk](http://dailytechvideo.com/video-271-rachel-rakov-using-python-for-sarcasm-detection-in-speech/) on the subject of sarcasm detection. It's about detecting sarcasm in speech, but it's related to the general problem. – alecxe Aug 24 '15 at 01:19

4 Answers4

18

Looks like there are studies that attempted just that, but they have yet to come up with a well working algorithm.

From González-Ibáñez, R. et al. "Identifying sarcasm in Twitter: a closer look"

Sarcasm and irony are well-studied phenomena in linguistics, psychology and cognitive science[...]. But in the text mining literature, automatic detection of sarcasm is considered a difficult problem [...] and has been addressed in only a few studies. [...] The work most closely related to ours is that of Davidov et al. (2010), whose objective was to identify sarcastic and non-sarcastic utterances in Twitter and in Amazon product reviews. In this paper, we consider the somewhat harder problem of distinguishing sarcastic tweets from non- sarcastic tweets

They conclude:

Perhaps unsurprisingly, neither the human judges nor the machine learning techniques perform very well. [...] Our results suggest that lexical features alone are not sufficient for identifying sarcasm and that pragmatic and contextual features merit further study

Here is another recent, relevant paper:
Reyes, A. "From humor recognition to irony detection: The figurative language of social media"

Enno Shioji
  • 26,542
  • 13
  • 70
  • 109
9

...sentences are written by users. Its a simulated conversation between 2 people.

Detecting the sarcasm is close to impossible with a single phrase, but with context it might be a little more doable. Let's assume that you can parse the sentence and interpret its literal meaning (not a trivial task, but that problem has been solved at least somewhat).

You now have context from:

  1. All the phrases in the conversation.
  2. The response of the other speaker.

Cross-Referenced Phrases

To leverage #1, you might cross reference all phrases with each other. Are any of them directly contradictory?

Example:

Speaker 1: I LOVE Justin Bieber. Do you?
Speaker 2: Totally! I love him.
Speaker 1: What's your favorite thing about him?
Speaker 2: His awesome music!
Speaker 1: Really? What's your favorite song?
Speaker 2: Come on, you know I hate his music.

We know have two contradictory phrases, "I love him!" and "I hate his music". There's at least a chance sarcasm has occurred.

Question or Response from Other Speaker(s)

Approach #2 could be more effective (or useless...perhaps the sarcasm is known but unspoken between the two parties).

Example:

Speaker 1: Justin Bieber is in town. I am SO going to see him.
Speaker 2: Ha.

Another example:

Speaker 1: I LOVE Justin Bieber. Do you?
Speaker 2: I have a giant poster of him above my bed.
Speaker 1: Yeah right.

Getting even more elaborate, you could apply a heuristic to determine how sharply the conversation deviated after a particular phrase.

Speaker 1: I am so totally into Justin Bieber!!! Are you?
Speaker 1 has made an emphatic statement
Speaker 2: Yeah, sure.
Sarcastic. We don't know that, but the other person in the conversation does.

What direction does Speaker 1 take now? do they change the subject? Depending on how sharply the conversation turns, it may indicate how they reacted to the perceived response.

All that said, most of this would require sophisticated processing and I would expect a very low accuracy rate at best. But it's a fascinating question.

Tim M.
  • 53,671
  • 14
  • 120
  • 163
  • 1
    I should add: The first example is good for finding if a user is lying rather, sarcasm is hit and miss though. Conflicting statements are very common from lies. Granted technically sarcastic statements are not commonly truthful so are also lies. Its a fine line :P – Sir Dec 31 '12 at 04:47
  • Agreed that you could easily detect lies instead of sarcasm...I thought the same thing. It would depend on the subject matter, but perhaps one of the parties is *ashamed* to admit that they *do* like Justin Bieber and instead of being sarcastic is actually lying to cover an earlier statement. – Tim M. Dec 31 '12 at 04:52
4

Sarcasm is really about the tone in which it is said, text doesn't hold vocal tone, also how feasible the statement is to being true can also determine if its sarcasm...

If the inputs are typed by users theres two ways you could do it.

One is based on what they write using internet lingo.

For example:

User might type:

"Yeah. Sure. I absolutely love him. /sarcasm"

You could do look ups for such keywords like /sarcasm [/sarcasm] etc


Alternatively you could use statistical odds:

"Yeah, and I'm the president of USA".... statistical odds of it being factually correct are so low it could be flagged as sarcasm.

Sir
  • 8,135
  • 17
  • 83
  • 146
1

So what is exactly sarcasm in a point of view of culture or language? If you want to resolve this complex problem you must clarify that. The problem is very complex because asks of using AI in therms of some human language. You can look at A.L.I.C.E. for some inspiration.

Mihai8
  • 3,113
  • 1
  • 21
  • 31