At the intersection of coding and creative writing, there’s singing and anxiety and happily ever after

AI4ALL Team
Nov 8, 2017 · 4 min read

Guest post by Nandita Naik, Stanford AI4ALL ‘16

AI4ALL Editor’s note: Meet Nandita Naik, a 2016 Stanford AI4ALL (formerly SAILORS) alumna. Below, Nandita takes us behind the scenes of her work with generative natural language processing, which she uses to create algorithmically generated poetry.


For a long time, I’ve nurtured two interests: coding and creative writing. Competitive coding is like solving a puzzle. You’re given a problem, now find an algorithm to solve it. Ready, set, go!

Creative writing is more like the process of designing a puzzle. You use language to evoke an emotion, then dive behind the scenes and craft your characters to convey that feeling. Creative writing was a part of my life that I honestly never believed could mesh with coding. How could it? How can computers express emotion?

At Stanford AI4ALL, I learned about natural language processing (NLP). We listened to lectures about computational linguistics. Also, my group research project focused on NLP, classifying tweets for disaster relief.

When summer ended, I kept what I had learned at Stanford AI4ALL in the back of my mind. Sure, computers can understand words. But can they put words together in an expressive way? This question sparked my interest in generative natural language processing.

Nandita Naik (standing) discussing Naive Bayes at Stanford AI4ALL 2016

During my sophomore year of high school, I built a recurrent neural network that writes poetry. It is trained on a poem I wrote and some English romance novels. Here are some of its lines:

i skateboard the forest ravens to her i was me dream of the tell of forest from the forest of those we her steel i steel of nests was i was a me deny her nothing! tumbling my i was the forest we a the forest and the yellow and the wild and the he?

Making this poetry generator got me thinking about meshing coding and literature. I had found a place where I belonged.

To summarize technical details, my project was structured as a five-layer LSTM. In Stanford AI4ALL, we learned about scikit-learn, the machine learning library. I used a similar library called TensorFlow.

Getting this to work was a struggle! Initially, it was overfitting like crazy. Overfitting is when your machine learning algorithm fits too specifically to the training data. In this case, my network generated nine pages of the word “and.”

To fix this problem, I implemented a dropout layer. Dropout is a technique to prevent overfitting. The way it works is you randomly drop some of the outputs from the neurons.

While a lot of what my network wrote was frivolous, there were some lines that I found relevant to thinking about AI’s relationship to humanity. Take this line:

singing and and the warnings and the anxiety: and the fright.so and the battle — there and and the and the romance,” and the happily, and the and

Here my network is connecting actions to commonly felt feelings. Connecting “singing” to “anxiety,” for example, is really common amongst humans, and I think it’s cool that my network was able to learn this relationship. Also, we can see it has learned the grammar of a quotation mark (while not doing so well with periods)! In addition, it picks up on the relationship between the word “romance” and “happily,” which is very important since we think of romances as ending happily ever after.

I think this line has insight. It sounds startlingly human — connecting fear and a battle, romance and happiness, singing and anxiety. Fear and insecurities are deeply human emotions, and I’m proud that my network is learning to capture these in language.

Going forward, I want to keep learning about the intersection of coding and literature. Stanford AI4ALL showed me what natural language processing could do. Seeing a computer put words together and create emotional depth was inspiring. Now, I feel that I know where I want to be.

About Nandita

Nandita Naik is a junior at Proof School who attended Stanford AI4ALL (formerly SAILORS) in 2016. She is interested in computer science, music, and literature. She has published poems in Canvas Literature Journal and Polyphony HS, and online in the Rising Phoenix Review (here and here). She competes in the USA Computing Olympiad (USACO) Gold division, and co-founded and taught at creAIte, a 2-day neural art workshop for teenage girls. She teaches a biweekly algorithms class at HackerDojo to get girls introduced to competitive coding.

AI4ALL

AI4ALL is a nonprofit working to increase diversity and inclusion in artificial intelligence. Our vision is for AI to be developed by a broad group of thinkers and doers advancing AI for humanity's benefit.

AI4ALL Team

Written by

AI4ALL is a US nonprofit working to increase diversity and inclusion in artificial intelligence.

AI4ALL

AI4ALL

AI4ALL is a nonprofit working to increase diversity and inclusion in artificial intelligence. Our vision is for AI to be developed by a broad group of thinkers and doers advancing AI for humanity's benefit.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade