Let's Generate Paper Titles
- Authored by John D. Boy
- Permalink
Inspired by this toot and using this tutorial -- both by Allison Parrish, who gives the greatest talks on computer-generated poetry -- I trained a recurrent neural network and had it generate some paper titles based on entries in my bibliographic database (available from here). Fun times!
In [1]:
from pybtex.database import parse_file
from textgenrnn import textgenrnn
In [2]:
bib = parse_file('Everything.bib')
In [3]:
english_entries = [entry for _, entry in bib.entries.items()
if not 'hyphenation' in entry.fields.keys()
and 'title' in entry.fields.keys()]
In [4]:
all_titles = set()
for entry in english_entries:
if 'subtitle' in entry.fields.keys():
all_titles.add(': '.join([entry.fields['title'],
entry.fields['subtitle']]))
else:
all_titles.add(entry.fields['title'])
In [5]:
len(all_titles)
In [6]:
textgen = textgenrnn()
In [7]:
textgen.train_on_texts(all_titles, num_epochs=3)
And here they are -- generated paper titles in increasing order of craziness (the higher the temperature, the more the generative algorithm deviates from the learned probability distribution)!
In [8]:
textgen.generate(10, temperature=0.7, return_as_list=True)
In [9]:
textgen.generate(10, temperature=0.8, return_as_list=True)
In [10]:
textgen.generate(10, temperature=0.9, return_as_list=True)