To Boldly Go Where NLP Has Gone Before: ST:TNG Auto-Generated

Brent B
4 min readMar 30, 2019

--

Over the past few months as I’ve experimented with some of the fast.ai NLP models, I was able to create a Tommy Wisseau Bot and create a script for a sequel to the Room (link below).

This time my goal was to build upon that previous experience but utilize the more recent fast.ai datablock api. I created a few simple functions that can be utilized to automatically generate dialog for a particular list of characters.

def ConversationLinesRecursive(characterList, numberOfLines = 5, temperature = 1):
“””Accept a list of character names. We reject any sentences that do not begin with these particular characters.
The same character will not speak 2 times in a row.
Continuously Feeds the past dialog in to generate the text”””
N_WORDS = 100
dialog = “”
lastCharacter = str(None)

#Put the character list into all uppercase
characterList = [character.upper() for character in characterList]

#We generate the number of lines
for i in range(numberOfLines):

#Keep creating lines until we have one of the characters
while True:
line = learn.predict(dialog, N_WORDS, temperature=temperature).split(“xxbos”)[-1] + “ xxbos “
#Who is the current speaker for the line?
currentCharacter = line.split(“ “)[1]
if (any(character in line for character in characterList)) and (currentCharacter != lastCharacter):
break

dialog = dialog + line
lastCharacter = line.split(“ “)[1]

dialog = dialog.split(“xxbos”)[:-1]
dialog = [line.lstrip() for line in dialog]
return dialog

The main concept here is the idea that we can utilize deep learning to enhance creativity. If one were to need to quickly bang-out some generic copy, we can create thousands of arbitrary lines and select the best for our purpose.

One other interesting idea to explore involves changing the “temperature” of the model, or its propensity to select more or less likely predictions for text. I played around with a helper function that creates n lines of text with a temperature value that is evenly distributed between these two values.

def GetCharacterLines(character, numberOfLines = 1, temperatureChange = True, temperature = 1.0):
N_WORDS = 150
EPSILON = 0.1
#We predict the next N_WORDS
#Each iteration increases the temperature of the sentence. We interpolate between 0 and 1.
if temperatureChange:
predictedLines = list(learn.predict(character.upper(), N_WORDS,
temperature=EPSILON + (i/(numberOfLines-1))).split(“xxbos”)[0] for i in range(numberOfLines))
else:
predictedLines = list(learn.predict(character.upper(), N_WORDS,
temperature=temperature).split(“xxbos”)[0] for i in range(numberOfLines))
return predictedLines

Below is an example of the type of output produced. The first line in the list is the most likely occurrence that Picard would say, while the last line is more unlikely.

['PICARD : : What is it ? ',
"PICARD : : You 're right . You 're not going to be here . You 're going to have to be here . You 're going to be here . ",
"PICARD : : It 's all right , Ensign . Mister Worf , you 're going to be all right . ",
'PICARD : : Mister Data , what is your current assignment ? ',
"PICARD : : He 's not a man . He 's a Starfleet officer . ",
"PICARD : : Do n't worry . He 's a fine officer , but he 's not very frightened . ",
"PICARD : : That 's true . But we have n't heard a Ferengi . ",
"PICARD : : Number One , they 'll sit down . ",
'PICARD : : You could possibly have something to worry about , Counselor . ',
'PICARD : : It would be Coalition territory if the Alliance fell to the breach .... ']

Now for the fun part. Here was the start of a random script. I simply copied and pasted generated lines for a somewhat comprehensible ST:TNG script.

PICARD ( V.O. ) : : Captain ‘s log , supplemental . We have arrived at Starbase Two — twenty — seven . We are in orbit around Beta Agni Two for the Federation and have agreed to contact the Enterprise .

DESCRIPTION : : As Riker , Data , Worf , and TWO N.D. SECURITY GUARDS ENTER . Riker ENTERS , looks around the room , sees a small ALIEN TRANSPORTER CREWMEMBER standing near the cell door . He casts a glance over at the Lieutenant .

DATA : : i am capable of emitting a highly internal reading . However , the secondary systems are very unstable , too

WORF : : Lieutenant

DATA : : i am aware of the risks involved . Doctor Marr is very curious about the

RIKER : : Captain — we ‘re going to need your help .

RIKER : : That ‘s right . The Romulans have crossed into the Neutral Zone . You ‘ve taken a weapon from Khitomer . They ‘ve told me you ‘ve failed in their mission .

PICARD : : It ‘s not why you came here . When i was a boy

RIKER :

PICARD : : Geordi … we ‘re in the midst of a Red Alert . You have to leave now . If you

RIKER : : They ‘re waiting for us . You

PICARD : : The Federation ‘s finest specialist in communication with Alpha state , and who has unique skills … and eight hours of stellar physics . We will be able to determine that this Beta Stromgren system will be following this action with

PICARD : : Mister Worf

RIKER : : But

PICARD : : Worf , what

RIKER : : i ‘m not sure . i think there ‘s a lot of interference from the Romulans . We ‘ve tried to shut it down — but we ‘re not going

PICARD : : Mister Worf … do you have any idea what the Duras

RIKER : : No . You were Starfleet ‘s finest specialist in communication with Cardassian

--

--