An artificial one-liner generator

320px-Zach_Weinerby Zach Weinersmith

The following is an idea I’ve been mulling over and talking to friends about for a few months. I thought I’d finally share it to see if anyone liked it or was interested in working on it.

Warning: evolutionary psychology just-so story to follow. Think of it as a parable, not as a theory. It’s just here to contextualize the idea that follows.

The Story

Suppose there’s a monkey. Suppose also that the monkey has evolved to have an inbuilt proto-toolmaking behavior.

For this specific example, let’s say he’s learned to snap a twig off a tree and stick it in an anthill. When he pulls it out, it’s covered with tasty protein-rich ants.

This monkey is unlike you and I in that he takes no pleasure in finding the right stick. He knows the stick must have certain qualities – long, thin, not too brittle. However, he does not experience any pleasure until he actually eats the tasty ants.

Suppose this monkey represents a species. This species does well because it has this one trick for getting protein out of the ground in abundance at a low cost.

Now, suppose one day a monkey is born who has a quirk. Instead of taking pleasure only in the ant part, he takes pleasure in the stick selection part too. That is, when he finds an appropriate stick, his brain rewards him with premature pleasure. So, whereas his brethren experience pleasure only upon eating the ants, this one monkey gets pleasure from selecting an appropriate branch.

This confers an advantage on that monkey. The other monkeys will select an appropriate branch, then use it until it breaks. This new monkey will change branches often until he finds the best one. Because he enjoys the selection process per se. He doesn’t know why he enjoys it, but as a result, he tends to get more ants per twig. He enjoys making the best twig for its own sake as much as he enjoys the inevitable payoff.

His mental pathway, simplified, goes something like this:

Confusion —> Understanding —> Pleasure {CUP}

Over evolutionary time, all the monkeys have this pathway, and it becomes a point of competition. The supply of good branches is limited and it takes work to select the best one. So, selection rewards the monkey who can go from confusion to understanding the quickest.

This pathway, originally useful for twig selection, leads to other beneficial effects. The monkeys now have the desire to understand systems. One day, a monkey finds a sharp rock and decides he wants to understand how to make sharp rocks. He creates the first hand ax, and outcompetes his brothers.

And so the mental pathway, CUP, gets strengthened and strengthened, producing useful results over time. We could set up an equation that looks something like this:

Level of understanding from, denoted by some value from 0 to infinity (potential size depends on complexity of thing being understood) = U

Amount of time taken to go from one value of U to another = T

The equation would be:

ΔU/T = Quality of monkey brain.

If it takes a long time to go from confusion to understanding, the monkey is a bad tool maker. If the time is short, the monkey is a good tool maker. In general, a higher ΔU/T score is a better toolmaker.

It goes without saying that the equation for U could be complicated and dependent on many things. For example, a stupid musician would understand sheet music faster than a very smart person with no music background. However, in cases like these, we could still find the latter to be the better brain. After all, the musician may be going from U=99900 to U=99950 while the non-musician may be going from U=50 to U=99950. So, the non-musician’s longer time needs wouldn’t necessarily indicate lower intelligence.

Over evolutionary time, ΔU/T should increase. The more selection pressure on toolmaking, the faster it should go up. Although this is generally good, it results in some perverse side effects.

For one, the monkeys now indulge in behavior without a clear evolutionary payoff. For example, they make up riddles for each other to solve. Sitting in the dark of winter with no natural puzzles to solve, they invent puzzles for each other, to generate pleasure for its own sake. These puzzles make use of a new concept – cleverness.

Here, you can think about ΔU/T in a second sense – how good a puzzle is.

If it’s too easy (What has two wings and a beak?) ΔU is small. So, the possible ΔU/T is limited.

If it is too hard (What is the product of the first 400 Fibonacci digits. Please solve using multiplication only) then T is too large compared to ΔU.

If it is non-inferable (What’s my middle name?), it’s no fun because you can’t solve it, so there is no change in understanding.

A clever puzzle threads the needle. For example, the classic riddle from The Hobbit: “What box has no hinges, key or lid yet inside golden treasure is hid?” The answer is “an egg.” Within reason, it is the only possible solution. It is also not obvious. It requires you to make inferences about what is acceptable in the category of “box” and “treasure.” In this case, the ΔU/T is at some favorable ratio.

It is fun because it uses the confusion-understanding-pleasure (CUP) pathway. In the golden treasure example, the question presents confusion. After some thinking, it leads to understanding. The reason the CUP pathway exists is for the advantage it conferred in toolmaking and strategizing. However, it’s existence also makes for a peculiar monkey behavior called puzzles and riddles. These behaviors are mere byproducts of the natural selection for monkeys who derive pleasure from understanding.

Now, suppose these monkeys come up with a couple of versions of the game. They have games, they have puzzles, they have riddles, and they have jokes. They conceive of these as different things, when in fact they’re just points on the ΔU/T line. The game lets you move slowly from non-understanding to understanding as you begin to comprehend all the possible tactics. The puzzle is like the game, but a bit faster, and with less to understand. The riddle is faster still, and has the bonus of essentially allowing you to make a discrete jump from non-understanding to understanding, once you catch the answer. The joke is nearly instantaneous. It takes you from complete confusion to complete understanding very rapidly.

For example: “Why did the church hate Dungeons and Dragons? Because it’s a form of birth control.”

The confusion is very brief, and concerns why there is a connection between Dungeons and Dragons and birth control. However, making the connection requires only a short chain of inference. So, the CUP pathway runs very quickly, and all the pleasure comes at once.

Thus, the game supplies a very large amount of pleasure over a long time. The puzzle supplies a smaller amount of pleasure, but in a shorter time. The riddle supplies even less pleasure, but in shorter time still. And the joke supplies the least pleasure, but it supplies it in an infinitesimal amount of time. When these things are combined, they result in more pleasure still. They all combine readily, as each is just a different member of the same family. Many jokes, for example, could be rephrased as riddles.

If true, this would explain why pleasure is experienced in all these things, and it would explain why pleasure is often more acute but less profound for jokes – they supply the highest ΔU/T, but the lowest value for ΔU.

It would also explain why people sometimes laugh when understanding a concept or solving a mystery. These are all just expressions of CUP.

The enjoyment of jokes has two prominent aspects – pleasure and laughter. Their pleasure may be explained by the above. The laughter could possibly be explained as follows:

The good problem solvers are the best mates. Thus, it benefits a monkey to signal understanding of a concept. In this case, the fact that the noise is a “HA” made at the back of the throat could be entirely arbitrary. It could just as easily have been a click or a bark.

This would have some implications that could be tested. For one, it would mean that a person is more likely to signal amusement (via vocalization and facial expression) when there are other monkeys to hear. That person might also be more likely to vocalize when the concept understood is an especially tricky one.

I suspect this is the case in humans. For example, if you just understood something interesting, where would you be most likely to vocalize – near other members of your social group or at home alone? Are you more likely to laugh out loud when watching a movie with friends or when watching it alone?

Similar behavior has been seen in human female sex vocalizations. For example, in some primate species, females are more likely to vocalize during sex if males can hear.

ΔU/T would also explain why dissected jokes are never funny. For the joke to have the proper ΔU/T, T must be very very low. When jokes have to be explained, T gets bigger and the joke becomes less pleasurable.

The Logic

I don’t know if the above is true, but I suspect something very like it, in principle, is. If so, it has implications for how jokes are written.

It means the ideal joke presents something confusing that can be quickly understood with a key piece of information. I propose that you could in fact write a fairly simple program that would create at least a certain type of joke. With modification, it could potentially handle more types.

The general way in which this type of joke runs is as follows: two things are at first glance unrelated, but then shown to have some relation in a sensible way. The above Dungeons and Dragons joke is an example. The perception of the joke proceeds as follows:

Understanding the church is involved.

Understanding the church opposes D&D.

(Note, so far, everything is just empirical statements)

Changing D&D to mean birth control.

(Note, the new statement is confusing, but still maintains all prior logical connections. That is, it’s still something the church dislikes, and it’s related on at least one metric to D&D)

Confusion over whether the statement makes sense.


Pleasure. (Hopefully)

Many classic jokes follow this format. For example, “Take my wife. PLEASE!”

An understandable statement is made – “Take my wife.” The meaning of the word “take” is altered, but all logical connections are maintained. Brief confusion results. The confusion is followed by understanding – the comedian means a different statement that maintains all prior logical connections. Once understood, pleasure results. Note the pattern – sense, nonsense, sense, pleasure.

(Of course, in the above case, we all know the joke, so ΔU = 0. But, the first time it was told, this would not have been so.)

For another example, I once wrote a joke in which Jesus tells his disciples to give all they have to the poor. This results in the poor’s economy crashing because the free product puts their economy in a deflation.

This joke follows a similar structure. You are told that Jesus favors helping the poor and is acting in a way to harm the poor. This results in confusion. When the connections are explained – dumping product results in deflation – understanding results. Once again, an idea (giving to the poor) has its meaning changed in a way that preserves logical sense but alters the meaning of pre-existing connections. Ideally this happens quickly, and the reader will laugh.

Note that in both cases a connection is discovered. In the first case, there is a strange equivalence. Imagine you discovered it by doing the following:

Start with a concept. Build all possible relations off of that concept as bridges to other concepts. From each of those concepts, build more possible relationships to more concepts. Eventually you have a branch tree. At some point, you will have a situation where you fork off of a concept, only to have the paths come back together. The following is an example:

1) Church opposes->D&D->is loved by->Geeks->who have->no sex

2) Church opposes->Birthcontrol->whose methods include->abstinence.

You can see that we fork from what the church opposes, only to “close the loop” at not having sex. This is, of course, simplified. In an actual diagram, “church opposes” would branch to many things, as would D&D as would “is loved by” and so on. We’re just creating chains of relationships. Saying geeks have no sex might seem like cheating, since it’s similar to a joke. However, consider it as being one quality of a stereotypical geek among many. Others might be shyness, social awkwardness, etc.

Here’s a doodle of a more worked out chart, that is still obviously rather artificial.


The point here is that we follow the perfect structure of a one liner via this pathway. When we find one of these loops, it represents a surprising shared relationship, which is essentially how we described jokes above.

So, structurally, this whole diagram would look like lots of nodes with lots of links coming off each node. To find the potential jokes, we simply need to look for these “closed loops.” That is, places where something forks, only to recombine later.

My suspicion is, based on the ΔU/T concept, that there is an ideal size to the loop. Too big a loop would require too much inference, thus making T large. Too small a loop would make ΔU too small and the joke would be dull. The ideal joke takes a second to understand, but only a second. So, there is probably a desirable length for a closed loop.

In addition, note that there are two types of closed loop. I’m calling these Loop of Equivalence (LOEq) and Loop of Contradiction (LOCo).

In LOEq, connections proceed from a fork until two places contain the same thing: e.g., fork from things the church hates to reconnection at lack of sex.

In LOCo, connections proceed from a fork until two places contain perfect contradiction: e.g., fork from things Jesus wants to reconnection when one end is “alleviation for the poor” and one is “suffering for the poor.” Jesus wants the poor to be alleviated and suffer.

In LOEq, the reader is presented with a strange equivalence that is then resolved, along the CUP pathway.

In LOCo, the reader is presented with a strange contradiction that is then resolved, along the CUP pathway.

The Program

Thus, to make a program, one would need to do the following:

1) Acquire many concepts

This could be accomplished by creating a website where people can enter nouns.

2) Acquire many relations

Suggest a noun to a website user, then ask for a relation that could come off it to another noun. For example, suggest the noun “star.” The relation could be “shines on” or “destroys” or “creates” or “is loved by.”

3) Acquire more concepts

Present the website user with subject relation combinations. For example, “Batman is loved by.” The user supplies a new thing, such as “The people of Gotham,” “Catwoman,” or “Comic Book Readers.”

4) Find similarities

Present users with similarly-connected or similarly-spelled things. For example, Jesus Christ or Jesus. The users identify when two things are in fact the same thing, thus reducing errors and false positives.

5) Construct the tree.

Note that at no point in this process do users input any jokes. They merely input concepts and relations. This is akin to a comedian observing the world. We’re just feeding the computer raw facts about the universe.

6) Search for loops of the ideal size.

If the program works, at least some of the time, the result should be a “clever” joke. With human assistance, it might be possible to pull out the good ones and make them into new jokes.

Limitations and Potential

It would be hard to make this program come up with longer story-based jokes. These require much more than just logic chains. In principle, the idea for a compelling story could be created using ΔU/T and logic chains, but the actual story itself requires a human.

Additionally, much of humor relies on unspoken concepts and context. This could be fed into a machine, but the output wouldn’t necessarily be a funny joke. For example, a raised eyebrow can serve to change the meaning of a phrase quickly from surprising to arousing. This is funny for the reasons above – it changes the meaning while preserving logic. It’s not clear how the proposed system would come up with the eyebrow rise, even if it came up with the arousing part.

In general, presentation would probably require human assistance. Once the loops are discovered, they have to be conveyed in a way that maximizes ΔU/T in the reader. It’s conceivable that a stock method could be determined for the machine to do this. However, that’d have the built-in limitation that it would be less funny every time it was used, thus lowering ΔU.

Discussion of Weirdness

This may seem like it shouldn’t work, since humans create jokes through something called “creativity” or “cleverness.” And, in fact, it may only work (if it works at all) for a certain class of jokes. However, in essence, it works the same way a comedian does. It is fed observations, then looks for a certain type of connection.

It has been said that a computer can’t make up a joke. However, neither would a person raised in a blank room. Humor requires observations in order to establish then subvert a logical chain. If a modern computer is incapable of joking, it may be more about the computer’s memory than its hardware or software.


Zachary “Zach” Alexander Weinersmith is the author and illustrator of the webcomic Saturday Morning Breakfast Cereal (SMBC) and of two other webcomics, the completed Captain Excelsior with artist Chris Jones, and Snowflakes, co-written by James Ashby and also illustrated by Jones. He also founded the sketch comedy group SMBC Theater with James Ashby and Marty Weiner in 2009.


60 thoughts on “An artificial one-liner generator

  1. I really like the ∆U/T explanation, it makes a lot of humor clear. I think another important aspect of humor is showing support of something (like how people always laugh at a joke that relates to them). If I wanted to be as cool as Zach and use math, Id call it “how specificly it relates to you” / “how mainstream you percieve it as”. A “Panderer” joke AI could ask someone their occupation and use an internet reference to find apt pandery.


  2. I don’t think you can say that something understands how it play Jeopardy if it cannot understand what “not playing Jeopardy” is. Understanding, roughly, is the ability to apply knowledge to novel situations which include significant deviations from past experience. Watson does not have that.


  3. I could only be that guy, but biting his tongue. Which I usually am.
    When I say “but that doesn’t make sense” people say “of course it doesn’t make sense, it is a joke”. This response puzzles me.

    I would have thought that a joke had to make some basic sense at its premise, even in order for that sense to be turned on its head.

    If it is based on something like “church hates D&D” or “church hates abstinence” then there is no sense to turn on its head to begin with.

    For me not to be that guy I would have to go my life without understanding from where humour derives and what it is that drives much of the rest of the human race.


  4. Interestingly, the “Geek” versus “Abstinence” relationship example is precisely why some people find jokes funny and others don’t find the same joke funny – if in one person’s experience, the two are a direct link (As in, Geeks are by definition abstinent – A “reasonable” assumption if you’re a young teenage geek) then a joke trying to link the two likely wouldn’t be funny. Whereas someone who requires a longer link between the two would probably find it very funny when they finally made the jump from Geek to Abstinence.

    Even “Chastity” to “Abstinence” could be funny in a joke if Chastity is taken (due to a person’s life experiences, or the context of the joke) to be a person’s name rather than the concept.


  5. Thomas,
    I’m not trained very well to tell jokes
    Again and again it has become clear that delivery is vital. Some people can make most things funny.
    Have you ever met anyone who has invented a good joke? There seem to be an endless supply of them but I have never met the inventor of a joke.
    Do any animals have a sense of humour? My dogs have a sense of joy but I have never detected anything that resembles humour.


  6. labnut, yes, I know some very funny, witty people. I even met a guy in a 12 Step program who was genuinely funny and was trying to become a stand-up comedian, and he “invented” some good ones. Delivery for stand-up comedians is particularly important. That requires some training and practice, I suppose. But what’s funny to one person is not necessarily funny to others. “Take Jerry Louis–veuillez!” That won’t be funny unless one knows that the French loved his slapstick brand of comedy more than Americans, and who also knew Henny Youngman’s joke too. There are so many types of humor that I doubt more than a few types could be programmed into a computer. And although I’ve know some jokes that were dogs, I’ve never seen a dog do a stand-up comedy routine. At least not intentionally.


  7. I believe the loop is not enough. There are other factors at play in the examples you have shown. Specifically, I believe you disregarded the social aspects of humor.

    For instance, the geeks/church joke deprecates geeks by reinforcing the stereotype that they don’t have sex. It is also deprecating religion for being irrational. When deprecating a group you are not part of, you elevate your own status in your own eyes. When you do it in a social context, you increase the cohesion of the group you are a part of. Those effects trigger some pleasure circuitry in out brains.
    Children will laugh at the statement “Billy is such a geek, he will never get laid”, assuming they know Billy, even though it has no loops. It makes them feel better about their chances of getting laid and their social rank.
    Sometimes people who are part of the deprecated group will also appreciate the joke, and be praised for having a sense of humor, but that is a mechanism for dulling the blow of the joke, which also brings them enjoyment.

    I also believe that the loops you have described are qualitatively different than simple understanding, and not just quantitatively. We are used to parsing language forward, and seldom need to go back to the beginning of the sentence to reevaluate its meaning. When that happens, we feel as if we lose our footing, and that induces a micro-panic reaction. When we regain understanding, we experience relief and release of tension, and that induces laughter.
    I’ve also heard that the laughter that is induced while being tickled is actually a mini-panic attack.


  8. I think this is a great simple model of humour. It immediately made me think of some of the twitter bots created by Darius Kazemi. Here is a good writeup of what he does: .

    I personally love his ‘Two Headlines’ bot that that takes two daily newspaper headlines and smashes them together in a somewhat arbitrary manner. For example, a hilarious one from just the other day: “Google reportedly testing Russia 4.4.3 update; to focus mainly on bug fixes”. In the case of the successful Two Headlines jokes we would be following your Loop of Equivalence mainly – and the fun for me I think is in finding the equivalences. As you say, they need to be quick, but not too obvious. Russia in the above does this for me quite perfectly.

    As an additional note, the really elegant bit of this theory to me is in providing a clear exposition of why explaining jokes isn’t funny – the T component is a very clever insight.


  9. Wow, this is interesting. There is, however, the fact that solving problems is rewarded “from the outside” during our whole lives, which could be an alternative explanation. It seems impossible to accurately test the influence of the environment on the motivation to solve a problem, so we probably won’t be able to tell if the reward is a consequence of operant conditioning or some “inherited” trait.
    My guts tell me this may be relevant to your theory: understanding a joke is possible for people who can understand metaphors, double meanings and implicit expressions such as facial expressions or body language. Solving problems, on the other hand, is possible for people with autism.


Comments are closed.