An Algorithm Wrote Five Hilarious Chapters Of Harry Potter

A natural language processing program was fed the first 4 books of Harry Potter. It then churned out 5 hilarious chapters.

14/07/2016 4:01 PM IST | Updated 16/07/2016 1:08 AM IST
AFP/Getty Images
Mumbai, INDIA: A young Indian Harry Potter fan strikes a pose in front of a Harry Potter poster inside a bookshop in Mumbai, 21 July 2007. The wait was finally over for Harry Potter fans who flooded bookshops worldwide to grab a copy of the seventh, last instalment of the best-selling boy wizard's adventures -- the volume that will seal his fate. After months of hype and hearsay, 'Harry Potter And The Deathly Hallows' went on sale globally. AFP PHOTO/Pal PILLAI (Photo credit should read PAL PILLAI/AFP/Getty Images)

Harry saw Harry's glasses. He took handfuls at the foot of the tree, and then walked forward, underneath its glass and beckoned to do something before he changed his wand. Harry had started face-to-face with her late, and then a sudden Death Eaters fed and Madame Maxime, but was left, not sporting red, white.

Confused? No, this is not a badly written paragraph from an unreleased book of Harry Potter. Nor has it been taken from any fan theory website. This is an excerpt from a chapter written by a deep learning algorithm developed by Max Deutsch.

An excerpt from chapter 2
Ron didn't even upset her little ingredients on the toilet, and a group of third-year girls last year. Highly bushy and then burst away from them quickly. "Thought you're all right?" he said.
Harry grinned at Harry. "Why should she be cheerful so while you gave detentions, Moody!"

Deutsch wrote a medium post recently which featured five chapters of Harry Potter written by the algorithm. As is obvious from the excerpts above, these chapters are weird. They have characters talking to themselves in a bizarre manner. There are a lot of structural mistakes too. But they are hilarious to read nonetheless.

Deutsch has described the basic steps on how the algorithm works.

  • You show a computer some sample text (for example, the Harry Potter books).
  • The computer identifies all the unique words in the sample text.
  • The computer groups words based on how often they appear together in the sample text (using a particular mathematical model). This is the "learning" portion of "Deep Learning".
  • You pick a starting word (for example, "The").
  • Using what it learned in Step 3, you ask the computer to guess the word most likely to come after the starting word (i.e. "The"). This is recorded as the second word.
  • Then, based on the first two words, you ask the computer to guess the third word. And so on.
  • Eventually, you tell the computer to stop guessing after many words, and you have successfully created your Deep Writing.

Then you have to follow the steps described in this blog to train the neural network. Technically this algorithm uses LSTM (Long Short Term Memory) Neural Network.

Excerpt from the chapter 4
Their carriage flew gold, and Dudley's hands through a corner, emitting rich crashing noise, the toad swerved together in a cool, empty sort of way. The Snitch was very impassive. "I know how best you just put him. Because he knows that everything is guarding?" Harry said.

A computer science graduate, Deustch is now working as a product manager at Intuit, which has developed the eponymous tax management software. Deustch is also a founder of Rhombus, a speed listening app, and has developed a website called which helps people create their personal websites to display profiles. He also creates great Lego paintings (Cue Prisma filter?).

The deep learning algorithm has also written an episode of the Silicon Valley, and a song from the lyrics of Hamilton.

More On This Topic