The history of intelligent machines is one of moving goalposts: Sure, a machine can do this, but can it do that? The “that” is often an achievement that strikes us as strongly connected to emotion—that seems especially human. A robot that can clean the crumbs from your living room isn’t nearly as impressive, or scary, as one that can leave you with a lump in your throat.

Poetry is a good place to move the end zone: it’s rooted in the inspirational and the comical—the deeply human—and yet, in many of its forms, it edges toward the computational and algorithmic. Poetry even seems to have been implicit in the bold 1955 manifesto that first announced the field of artificial intelligence, declaring that “an attempt will be made to find how to make machines use language, form abstractions and concepts.” The pioneers of A.I. never mentioned poetry outright, but, if you squint, you might see its spirit in their ambitions to investigate the “rules” connecting human thought with word “manipulation” and in their efforts to explore the relationship between creativity and randomness—not to mention in their grander goal of creating machines that would “improve themselves.”

There are more resonances between programming and poetry than you might think. Computer science is an art form of words and punctuation, thoughtfully placed and goal-oriented, even if not necessarily deployed to evoke surprise or longing. Laid out on a page, every program uses indentations, stanzas, and a distinctive visual hierarchy to convey meaning. In the best cases, a close-reader of code will be rewarded with a sense of awe for the way ideas have been captured in words. Programming has its own sense of minimalist aesthetics, born of the imperative to create software that doesn’t take up much space and doesn’t take long to execute. Coders seek to express their intentions in the fewest number of commands; William Carlos Williams, with his sparse style and simple, iconic images, would appreciate that. One poet’s “road not taken” is one programmer’s “if-then-else” statement. Generations of coders have taken their first steps by finding different ways to say “Hello, World.” Arguably, you could say the same for poets.

Many programmers have links to poetry—Ada Lovelace, the acknowledged first programmer ever, was Lord Byron’s daughter—but it’s a challenge to fully bridge the gap. Sonnets occupy something of a sweet spot: they’re a rich art form (good for poets) with clear rules (good for machines). Ranjit Bhatnagar, an artist and programmer, appreciates both sides. In 2012, he invented Pentametron, an art project that mines the Twittersphere for tweets in iambic pentameter. First, using a pronouncing dictionary created at Carnegie Mellon, he built a program to count syllables and recognize meter. Then, with a separate piece of code to identify rhymes, he started to assemble sonnets. For the first National Novel Generation Month (NaNoGenMo), in 2013, Bhatnagar submitted “I got a alligator for a pet!,” a collection of five hundred and four sonnets created with Pentametron.

Bhatnagar’s code required that each line be an entire tweet, or essentially one complete thought (or at least what counts as a thought on Twitter). It also did its best to abide by strict rules of meter and rhyme. This is how “Good night! Tomorrow is another day :)” (the titles are machine-written, too), begins:

I pay attention to the little shit

yeah, teacher aren’t trying anymore… :)

Not even going to encourage it.

I never been in twitter jail before …. Two people wanna be in my bio ?

I wanted some banana pudding to

Don’t be a menace is a classic tho

Know what’s amazing? Johnnie Walker Blue Another day another dollar tho.

Tomorrow is another awesome day

She going hard and he’s complaining so

I never liked Sabrina anyway. Fuck my retainer has a crack in it

This Maybelline mascara is the shit!!!

In Bhatnagar’s most recent collection of computer-assisted sonnets, “Encomials,” he relaxes these constraints. For a machine to produce work that sounded human-generated, Bhatnagar realized, he had to strike a delicate balance between accuracy and authenticity. “If it made too many mistakes, then it wouldn’t look human, so my hope was that it would be just enough mistakes,” he said.

On a whim, Bhatnagar looked in the debug logs of Pentametron, a repository of tweets that had been discarded because they were close to iambic pentameter but not perfect. Text in this trash heap had been stripped of punctuation and capitalization after being disposed. Bhatnagar built a new program to comb through this corpus and write sonnets with enjambed lines—that is, phrases that flow over naturally from one line to the next: