Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, September 27

Could an Artificial Intelligence Write a Book?

Could an Artificial Intelligence Write a Book?

I want to do something a bit different in this post. I’ve gotten more into programming lately (Python) and I’ve wondered: Could an artificial intelligence (AI) write a good novel?

Back in the day -- say 20 years ago -- we talked about AI but now we’re also discussing AGI, Artificial General Intelligence. That’s what we humans have.

If we create an AGI, and if this AGI can do pretty much everything a human can, will writers be out of work? [5]

(By the way, if anyone disagrees with anything I say here, please set me right! I find the field fascinating, but I’m not a data scientist. You can contact me on Twitter (@woodwardkaren) or leave a comment, below.)

Here’s the question I’m going to try to answer: Right now, is there a text generation program that could write a story that readers couldn’t tell was computer generated? And, if so, what would this mean? Would it put me out of business or, possibly, would it make my job easier?

Deep Tweets

Let’s get specific. Could an AI read all the books by a particular author -- say Stephen King -- and write a book that a group of Stephen King’s fans could not distinguish from Stephen King’s work? And I don’t mean sometime in the future, I mean right now.

Well, something like this has happened. Lex Fridman trained the text generation program GPT-2, created by OpenAI, on the tweets of several well-known people and then asked it to complete this sentence, “The meaning of life is …”

I encourage you to read the article, DeepTweets, it’s fascinating. The program nailed it. Not only did it give an accurate answer but it answered more-or-less in the voice of the person in question. [4]

For example, Fridman trained a neural network on Richard Dawkins’ tweets and asked it to complete the prompt, “The meaning of life is …” Here’s what it came up with:

“The meaning of life is complex and Darwinian. Evolution is a FACT.”

That’s creepily good. I think that's very close to what Dawkins would actually say.

OpenAI and GPT-2

But a tweet is one thing, writing a short story -- a good short story -- is quite another.
To reiterate, we want to know if a text generation program, one available to the public right now, could produce text that not only doesn’t look computer generated but closely resembles the work of a specific author. Specifically, could such a program write a book in the voice of Stephen King that would be so authentic that a panel of die hard fans couldn’t tell the difference between the fake and a real story by King?

I’ve done a bit of research and from what I can tell (perhaps I’m wrong, and if I am please let me know) at the present time the answer is: No.

That said, I think we’ll get there one day.


GPT-2 is, I think, the most advanced model we have right now, at least that has been made available to the public.

GPT-2 was created by OpenAI. To give you an idea what OpenAI’s intentions are, here is their (very short!) mission statement:

“OpenAI’s mission is to ensure that artificial general intelligence (AGI)—by which we mean highly autonomous systems that outperform humans at most economically valuable work—benefits all of humanity. We will attempt to directly build safe and beneficial AGI, but will also consider our mission fulfilled if our work aids others to achieve this outcome.”

As I mentioned, the program that generated this text, GPT-2, was created by OpenAI, a nonprofit lab initially backed by Elon Musk and other tech entrepreneurs. BUT this isn’t the most powerful version of the program.

OpenAI felt it would be too disruptive to release the most powerful, trained, model because it could be used to, for example, post comments or reviews that could not be distinguished from those submitted by a human author. That could become a problem.

Although the fully trained model of GPT-2 has not been released, OpenAI did release one that was almost good enough to use to generate text that couldn’t be differentiated from human generated text.

Here’s a prompt that was given to the program, for it to finish:

“In a shocking finding, scientist discovered a herd of unicorns living in a remote, previously unexplored valley, in the Andes Mountains. Even more surprising to the researchers was the fact that the unicorns spoke perfect English.”

This is what the program wrote:
The scientist named the population, after their distinctive horn, Ovid’s Unicorn. These four-horned, silver-white unicorns were previously unknown to science.

Now, after almost two centuries, the mystery of what sparked this odd phenomenon is finally solved.

Dr. Jorge Pérez, an evolutionary biologist from the University of La Paz, and several companions, were exploring the Andes Mountains when they found a small valley, with no other animals or humans. Pérez noticed that the valley had what appeared to be a natural fountain, surrounded by two peaks of rock and silver snow.

Pérez and the others then ventured further into the valley. “By the time we reached the top of one peak, the water looked blue, with some crystals on top,” said Pérez. 

That’s not all! If you’d like to read the rest of the story GPT-2 produced, check out the article. My take on reading this is that it's not bad! But I don't think it's a thread to writers.

Could AI Help Writers?

At the moment, AI isn't going to put us out of work, but can it help us?

The other day I came across this article from Vox: How I’m using AI to write my next novel, by Sigal Samuel. [2] He writes:

"While some artists worry that AI will put them out of a job — just as it’s expected to do for, say, truck drivers and factory workers — I’ve been more inclined to see it as a collaborator than a competitor. I don’t think AI will be good enough to write a superb novel on its own, but I do think it can be very helpful in a novelist’s creative process."

Samuel has been using GPT-2 to help him get over writer’s block. I could see that working! I’m glad he’s found something to help him keep writing.

If you’d like to download the latest version of CPT-2, there’s the link.


It took me longer than I thought it would to finish this post and I ended up not using some of the research I did. BUT, I decided to leave these notes in because the articles are interesting and I thought you might want to check them out.

1. The rise of robot authors, published by TheGuardian. 

2. How I’m using AI to write my next novel, by By Sigal Samuel over at Vox.

3. GPT-2: 6-Month Follow-Up. Published August 20th, 2019 on

4. DeepTweets: Generating Fake Tweets with Neural Networks Trained on Individual Twitter Accounts, by Lex Fridman.

5. The way I’m thinking about it, an artificial general intelligence would be able to tell jokes, it would have ideas about whether a certain stock is going to go up or down, and it could write a fabulous blog post! Basically -- and sorry to use a reference that might be a little dated -- an artificial general intelligence would be a lot like Data from Star Trek: Next Generation.

6. Here's something interesting: Hugging Face.

Tuesday, September 2

Guest Post by Chris Pitchford on Writing And Programming

Guest Post by Chris Pitchford on Writing And Programming

Today I’m going to do something a bit different. I don’t usually have guest posts, but when I discovered Chris Pitchford was coming out with a new book, The Agility of Clouds, I asked him to talk with us about his writing process, about how he—a programmer by trade—thinks about writing.

Take it away, Chris!

*  *  *

Programming is nothing like writing fiction, except that it’s totally like it.

I'm a software developer and a writer, and the two supposedly “non-overlapping magisteria" might be more connected than you might think. I'll leave the poetry of code as a discussion for another time, and focus here on similar processes. Writing a solid and engaging application is really like writing a solid and engaging story, at least, in how I view it all.

Bear with me please, as I go through my process of creating software. When I start building a new application, I start with the data involved as the core concept around which all the other elements are built. I define a model of the data, whether it's a username and password, or messages sent about, files uploaded or whatever. Even if I’m rushing and jump right in to building form elements within a user interface: a text field is different from a checkbox; they represent different data types. Those types become central to the development, and I make sure they are defined first.

But you'll notice—because you're clever that way—that in addition to mentioning the data model above, I mentioned software controls like form elements. The interface is just as important as the model, and the attention to detail in creating elegant controllers is the first thing a user will see and the last thing they remember. The last component of the application I build is the glue that binds the data model and the user interface. These views of the data are the transport mechanisms that deliver the pieces of the data from the database to the interface, and return the results of any interaction.

It all works very well, for projects large and small, in different programming languages and even different environments—mobile apps vs. server applications, for example. The whole process I just described is really just a design pattern, called in this case the "Model/View/Controller" paradigm, but how does it relate to writing? Well, that's the premise of this little article, and I appreciate your patience in staying with me so far.

So, let's just imagine I start writing a completely new story ex nihilo, my imagination the only thing that's filling a blank page with prose. Have I skipped the core foundation of the structure I mentioned earlier? Not at all, as the tone of the words I chose to write is one of those fundamental concepts. The model of the story, like the data of the application, is always present. Even if I'm not explicit about the style of what I'm writing before hand, I'm defining part of the model in how the words will follow my modest start.

Of course, when I write the actual words of the story, that is the interface that the reader will interact with. Their own imagination and background are as important as the words on the page; the story only comes alive when it's read. So, all the details of pacing, grammar, word choice and even dialogue attributions are part of the interface that helps the reader become immersed and merge with the story. But in order to get the details and the model to cohere, I have to have a plot, or glue that binds the themes to the details. After I set the model of the story that I write, I loosely outline the plot so that I can make sure the goals and results of the writing are revealed in the details.

Okay, that’s fine in theory; how does it work in practice? For my novel, The Agility of Clouds, I had originally focused on the character who was eventually to become the antagonist, Father Time. I outlined a story that followed his humble origins in Ireland to the English colonies in the New World before the Revolution, where his latent paranormal abilities would be awakened. His mentor would be the formidable Lady Seramis Helleborine, who became so interesting to me, she would eventually become the main character of her own book—the book I’m referring to—The Agility of Clouds.

But at first, the story was too dark, and I lacked a definitive theme—the reason why I was writing. For The Agility of Clouds, I decided on a theme very important to me to serve as the purpose of my writing: empowering women and minorities at a time of disenfranchisement and slavery. I further defined my style—specifically, the dialogue—to more closely match eighteenth century modes of expression.

With that new model in place, I created a new outline or view of my story. In this new outline, I plotted the development of the story as well as the emotional arcs of the characters. I made sure to cover the areas that would make the emotional connections I felt with the characters and their stories apparent to the reader. Then, it’s off to the races, and I will let you, dear reader, determine how the interface, or the actual text of the novel works!

*  *  *

Thanks Chris! A fascinating perspective; I'll never look at a user interface the same way again.

As I mentioned at the beginning of this post, Chris Pitchford's latest book is The Agility of Clouds. Here’s a bit more about Agility as well as the man behind it:
C. J. Pitchford is a programmer and peripatetic prog-rock paramour and parent, living in a neighborhood in Denver, CO named for a cemetery and a mental health institute. He wonders which one of those is where he will end up…

His newest release, The Agility of Clouds, a sailpunk adventure in the spirit of Edgar Rice Burroughs and Jo Walton, launched September 1. “Forced to spy for King George II of England by the scheming Lord De La Warr, Lady Seramis Helleborine faces the most dire enemy of all: Father Time. Of course, her enemies hadn’t counted on opposition from one of the most brilliant minds of the eighteenth century, as she pursues justice across the skies in her improbable airship, The Agility of Clouds.” Available in ePub for Kindle at, it is also available in an illustrated trade paperback edition at and in an illustrated iBook format at the iTunes Bookstore.
Photo credit: "Featherweight" by Daniel Zedda under Creative Commons Attribution 2.0.