Skip to content

Instantly share code, notes, and snippets.

@khturner
Last active April 5, 2017 12:57
Show Gist options
  • Save khturner/a0682b05165bf308de09483ee9979228 to your computer and use it in GitHub Desktop.
Save khturner/a0682b05165bf308de09483ee9979228 to your computer and use it in GitHub Desktop.
A neural net that generates Simpsons episodes

Soulless Sam Simon - A Simpsons script bot

First we're gonna get an EC2 instance up and running with the training data

# Run on an AWS c4.xlarge EC2
$ sudo apt-get update
$ sudo apt-get install r-base-core docker.io
$ sudo R

# In R now
> install.packages("dplyr")
> install.packages("readr")
> q()

# Back in bash
# Generate corpus
$ R -e 'library(dplyr); library(readr); simpsons_lines <- read_csv("https://query.data.world/s/7e781ukm08jf5tcfqfihu8vk3") %>% arrange(episode_id, number) %>% filter(speaking_line == "true") %>% transmute(output_line = paste(raw_character_text, spoken_words, sep = ": ")); write_lines(simpsons_lines$output_line, "simpsons_script_lines.txt")'

What's the training corpus look like?

$ wc -l simpsons_script_lines.txt
132036 simpsons_script_lines.txt # 132k speaking lines from 564 Simpsons episodes
$ ls -lh simpsons_script_lines.txt
-rw-rw-r-- 1 ubuntu ubuntu 8.8M Apr  5 01:23 simpsons_script_lines.txt # 8.8M file
$ shuf simpsons_script_lines.txt | head # Gimme 10 random lines
Poochie: Yes. I certainly do.
Comic Book Guy: "Lisa Simpson's unflinching, darkly comic family portrait is the can't-miss hit of the festival. Landspeeder, do not Bantha, to your nearest cinema to see Lisa Simpson stab her family in the back with her camera."
Seymour Skinner: What am I supposed to tell our children?
Bart Simpson: Now follow me!
Edna Krabappel-Flanders: My ticket to freedom!
Marge Simpson: My sandwich!
Homer Simpson: Why? I just saw the best part.
C. Montgomery Burns: Step lively, Smithers. That orphanage won't demolish itself!
Homer Simpson: Wow. How do you do that thing with your feet?
Homer Simpson: Aww. Innocent babies whistling nonchalantly. How sweet. Maggie will be back to play with you tomorrow.

OK looks good! Let's train this! Using https://github.com/crisbal/docker-torch-rnn

# Preprocess corpus for torch-rnn
sudo docker run --rm -v /home/ubuntu:/home/ubuntu/torch-rnn/simpsons crisbal/torch-rnn:base python scripts/preprocess.py --input_txt ~/torch-rnn/simpsons/simpsons_script_lines.txt --output_h5 ~/torch-rnn/simpsons/corpus.h5 --output_json ~/torch-rnn/simpsons/corpus.json

# Train! Change parameters if necessary (see https://github.com/jcjohnson/torch-rnn/blob/master/doc/flags.md#training for details). Run as a nohup so I can go to bed and check it tomorrow AM.
nohup sudo docker run -v /home/ubuntu:/home/ubuntu/torch-rnn/simpsons crisbal/torch-rnn:base th train.lua -num_layers 3 -rnn_size 256 -checkpoint_name ~/torch-rnn/simpsons/checkpoint -input_h5 ~/torch-rnn/simpsons/corpus.h5 -input_json ~/torch-rnn/simpsons/corpus.json -gpu -1 &

# Once in a while, sample output from the net. The average Simpsons episode comprises ~16,000 characters in the corpus
sudo docker run --rm -v /home/ubuntu:/home/ubuntu/torch-rnn/simpsons crisbal/torch-rnn:base th sample.lua -checkpoint ~/torch-rnn/simpsons/checkpoint_28000.t7 -length 16000 -gpu -1 -temperature 0.85

Soulless Sam Simon's latest episode after 28,000 training iterations:

Homer Simpson: Yeah, near it! What was I go? I was trying to put your name on the service for four is a pearlin.
Marge Simpson: All the test.
Kent Brockman: It's way to present a test of leg protection like that beer of others and kelease that I left a blood from "Bart's thing. So it's suiling me, I'll do that this new children here,115 "Mirks", there's more for the far and "are to Namellar night news fired in arsure. But take it when he is!
Homer Simpson: That underce children's most half to the most of the best different beer life works...
Kent Brockman: Stealing art crazy.
Bart Simpson: You have reading the cameras?
Bart Simpson: Wait a minute. Here we do is cowboys line on the way.
Beckletz: THIS WAY / AND DON'T HAVE A WART IT ALL SAFE ALL BABY BACK TO-FY!
Ribbert: I don't know you don't want to be chessed the head away the whole bedroom! Sorry, sexmber. It works.
Professor Jonathan Frink: Good to the storak for except murder than it.
Lisa Simpson: Uh, why have you got propected? Called it everything else are the rumbery first little angelstical plant of our great world for me, collapse to buy it.
Bart Simpson: Please... Mr. Simpson.
Marge Simpson: No. What does wouldn't remember the child because you're going to the reason? I've got water to contains. We are this sades of the dip store of the bus flesh I've saved the show of one cab-day.
Homer Simpson: Not the show!
Lisa Simpson: It's Lisa Simpson, then everything's a nice man.
Homer Simpson: Marge, you have a name to age.
Female Jack: I'm the first young numbers that they took a houseling car for three full children to that soap of a case of the house for the house boys.
Moe Szyslak: Homer? You don't want to raise Lisa Flanders to Duff Of Moe morning?
Homer Simpson: That's from Simpson. So, what did you see the fireman. He's not punishment so now. That's what you can't see it, boy.
Sideshow Bob: Now if I really think Itchy and Scratchy Troy Skins Lisa Simpson treedies has mine.
Bart Simpson: But I'm putting which the computer and if I died to this "number one dispity."
Bart Simpson: Rockwards, wally bird grab.
Saleswoman: Not if we refuged it gets to well had a suggestion for your own life, but who are you well, the guy in floor to appear at the back of an expertists tacked off our ravan?
Homer Simpson: Come on, Homer. We got more of your boogiesly modestroid that the king isn't workin' about my dudes for the house.
Mindy: Oh Homer, I am so dee boy.
Marge Simpson: I don't want to do that there steps like he's a check.
Bart Simpson: Well, you know, I know I had a five-four on the good butt.
Lisa Simpson: Cowage?
Lisa Simpson: So you don't know what you would get his main in our floor. It's finally not to be packed and led these fault.
Seymour Skinner: That's okay! Scooby The Professor Honor, the topic lady charce comics where in the same Army in this hopes 'cause the attractive men is prayer.
PERK OW MAN: Rumble hands! Oh, would you like to finish your life.
JANEY: That's right, pillow as I had our moments.
Homer Simpson: You knew when we had better than Tom A!
Mailman: The "Todk Careless angels" candidal before the son's film party to Basubake and I see you so collections. You're my negragr works, never holdline boss. Now honey? What? The list of soulerobots of take for one?
Ralph Wiggum: It's a movie, but none of you in a ridiculous like Fully's friends, we supplar a rap wherewim again.
Tom Brokaw: Old morning with us last four! Isn't there another hurt?
Marge Simpson: Stick is madked franchise, the ring an evil often trees closed.
Homer Simpson: Or you were gonna get back in what Lisa and fly to one...
Marge Simpson: Meletorious, little Moe's Guy. So, have you send her far blood?
Marge Simpson: I'm not a really saving some interest to come out of the canation of me and the winning they can fill 'cause he was sad, information. I'm sorry. I mean, if I try to go with Springfield would clear one things and I said I want to take a stranger. Um... I'll just get ready.
Homer Simpson: What the hell have more than ever, you kept me home, Marge?
Groundskeeper Willie: We already hear that in the sticks of spirit of commercial star.
Singers: I breathe yourself, Jack. I want him to your own biggest afternoon.
Homer Simpson: Uh... I'll get it.
Nelson Muntz: Yes. You're my career!
Nelson Muntz: Oh, look at that kid, I can't do it, the summer was a egg.
Lisa Simpson: Maggie. I have a book while you could live in the ring!
Homer Simpson: Nobody is innocent yard and dress.
Homer Simpson: Oops.
Homer Simpson: Boy, quick, man. But I'm a fame shows. I love you. Look!
Homer Simpson: But spent the head!
Homer Simpson: Congratulations, Lord!
Nelson Muntz: Haw haw!
Homer Simpson: You know what your back I touch a good time, brothering to Ghinky Univer War Tremetimon was finally going to fire the man saved a sun?
Lisa Simpson: Look, there's nothin' what did you think about you, Marge?
Young Leftorive: Make up in the sponse-- which I thought I just could use your face and space nature's joint?
Lisa Simpson: Kids, we could invite a million dollars. And I have a raise and carpets!
Auctioneer: Put a second. Fall nepters might be at the police or that little girl.
Marge Simpson: That's it.
Lisa Simpson: I'll give you any good pants of work, uh, you've score this time, three... Arch -- don't worry, Homer. Guys are crazy my rock of an hour and meeting out of dollar with this life and excuse me, Chaunnel...
Bart Simpson: Hey, Lis, I've got Skinner never had a thure statement. Something belvails.
SCARY MAN: Make it ten thing, Marge.
Lenny Leonard: Hey, what happens have Billy Snipen Truckler's Mexicane?
Sideshow Bob: Oops, finish Homer. They make me first thing we said... Someroller's of a pilot from my life, I beg my eyes.
Marge Simpson: On the smiley wears and night?
Homer Simpson: Oh, I'm gonna show you our houseworks!
Chief Wiggum: See how to know that it was confused! No, it's a married.
Homer Simpson: Oh, that's for people shready every school and mall.
Lisa Simpson: Mr. Simpson, isn't that worse of entitled alternatrities?
Homer Simpson: Let off me to me!
Lisa Simpson: I love you, Moe. On trouble. Just because they know what I got the chain of many best of it. Who are you will say?
Rev. Timothy Lovejoy: What'd I do?
Homer Simpson: Be can relax. Oh, of course.
Lisa Simpson: Oh, wool, what are we gonna do there work?
Marge Simpson: Where's your President? Is he just got very pain by Relations?
Squeaky-Voiced Teen: Let's go take a top and I have research a psycholicac men ended into the trullown for seltistment.
Homer Simpson: Okay, name. That was my breaky.
Moe Szyslak: Now A-breakfast! Just the worst cure and when I'm afraid we don't think about all the greatest unpret thinking today has been asked with a little tax, ancordnessfully none of the time in your fans.
Bart Simpson: There's no accident of this extra-in car.
Lenny Leonard: I don't know what I killers in the eating people's right for somewhere and I actually report the backup on my special hearts.
Bart Simpson: God needs your self, I suppose they will.
Krusty the Clown: What?
Bart Simpson: But I want you to tank cards?
Operators: Have I Springfield. Ooooo, guys. That's ha start to my sons.
Homer Simpson: Now...
Policeman: With if Mr. Burns! Stop your sleeping cocklame sense and see that a British Fly one hours.
Homer Simpson: The nuclear plane wallets crazy from the name of the United Corporation Chunky -- not cost the cripplings.
Bart Simpson: Could that sounds like they say? Look, I heard at the Cesar Creek and Dr. Licensed Lamance.
Marge Simpson: Why are you sure if they are issued the roll that workers?
Homer Simpson: That's right, Professor Modernie.
Lisa Simpson: I'll cover you, but it's only too dance.
Marge Simpson: Oh, you've alive to interrect a personal.
Bart Simpson: I'll be blessing what I'm supposed to be happy to do.
Homer Simpson: Marge, it was the beeper says...
Lisa Simpson: You know sir, then he got the time in a Book machine.
Homer Simpson: Mood, I've been Lape would desire control.
Chief Wiggum: Well, they're supposed to get a bunch of silent and request.
Grampa Simpson: Yes, sir, you can get some help.
Marge Simpson: The togniked yourself is so bed.
Nelson Muntz: Haw left.
Lucille Lewis: What about yourself. Let's see... seriously. You're smart convention.
Homer Simpson: That's the best small three hundred the trullas, huh? Just assassing little month to make Homer To Chetter Cable Collier.
Homer Simpson: Indeed.
Homer Simpson: Oh, what about our fakes three contest.
Homer Simpson: Oh, Daddy.
Bart Simpson: The "Level gifted by the expensive dreams" now with an eight respect" about beer-beer.
Marge Simpson: Uh... this family are our daughterry.
Bart Simpson: Wow, that was another cent of some of that gone. Bye!
Chief Wiggum: No, no, no, no, I'm sorry.
Bart Simpson: Let's see why I should stay for it, and the three McBain Grampa is good at the grench of policeman.
Homer Simpson: Oh Lord, dammit! Mmm, that's what it's our wife and call you pray when I call Dinner and Homer and Frink Leverant Bonney of the messive night.
Lisa Simpson: Wait, that was willing and see what I never hope I'm only been saying.
Homer Simpson: I kinda win working for up next to the rest of the Lord of "Ilure Aggsseady"... The Lindsay do whatever they have a hold certainly eyes of his professor soul and family as asked out there and better than my beloved politics. And the teletime cake" whose drinkenstees because the train as much for the chogger, you're brilliant. That's it. You're safe of idiots!
Marge Simpson: Well, he's taken his autograph!
Otto Mann: Yeah!
Homer Simpson: Hey, please. I really should do the power.
HANK CHANDING: That's on Corpy.
Bart Simpson: This house is movie!
Marge Simpson: Oh, that's everyly people about Milhouse and Memory... eliminated today's got a cosque the truth lock it off.
Homer Simpson: What? Why am I?
Edna Krabappel-Flanders: THERE YOU DON'T YOUR COUNTURE / SOME FAMILY / I DEEATH ROW IT'S THE BIRLY / SOCPLE...
C. Montgomery Burns: Excellent. You were tickets can't let together that it will give beliefs. You don't want to buy your taxiring that Super-Best Activities and the scoutins are really ask you a guy who... Two the buzzle?
Homer Simpson: Fine.
Homer Simpson: I got the topics. Thanks like a test.
Homer Simpson: But I have a selfish scares.
Bart Simpson: Well, are you going to watch me in alley?
Homer Simpson: Okay, that was a wig feet.
Lisa Simpson: Um, Starpially since I can have the only crazy problems to money yourself, but it'll eat a pretty cell slavery and witch by a point of your thought then the gross marriage was talking about Sunday get outta the ponding summer.
Cottley Hight: I don't like the house! Our after thrill about Larasm.
Bart Simpson: Dad, my board did have owned to spirit.
Lisa Simpson: But I really forgot how to speak you to keep the whole yoo that happened. You think I want to see!
Lisa Simpson: Well, I don't think this is the city of the way.
C. Montgomery Burns: I was just telling you like your daddy.
Ned Flanders: Well, you should put the eight years ago, I'm not gettin' a chance.
Homer Simpson: Woo hoo! Listen, still.
Homer Simpson: I want you in a wedding out of the solution with the principal's let-madfather to be skin.
Homer Simpson: Nollate Mat. So, what? You're cheesed yet. You want to get a crush? When you're Customer.
Krusty the Clown: Ow, we once old summer has as been care of that knibulouse of hose maker where o'er Maggie Shoe sexmbere neighbors.
Girl: Well, now you're right.
Homer Simpson: Hey, Bart, it's time to "Grawn" in the cents' feelin's in an easy where these.
Seymour Skinner: Is there something Christmas trial is sleeping in the bar?
Bart Simpson: As for good baskets, we gave hired into my country as I am monnally boiling this weight!
Ron Howard: No solid.
Bart Simpson: Sorry...
Lisa Simpson: What? I got all me two hundred thousands.
Lisa Simpson: What?
Homer Simpson: Oh, I smell sometime. Soon you're fully as really attract the roof I crushed to... I almost seen his boy. And I said you wouldn't be easy highways in the Imagans.
Fat Tony: Ah. See you all!
Kent Brockman: And Bart, the internet name is so much crys in a hard.
Marge Simpson: All right, sick them in charges of all.
Homer Simpson: What? There's pretty solved my tennis perfect thing.
Lenny Leonard: They got a crime feels a spare ends and skaters and skinny convincingly scriptions.
Homer Simpson: I think I want Macahas People.
Waylon Smithers: I bet you could spend the mood has to be Laster Jacket and Homer.
Bart Simpson: Yayyy!
Marge Simpson: I mean, strike!
Marge Simpson: Kids, good-remousive, boys.
Homer Simpson: Let's go, Ned.
Homer Simpson: Hey God, why would you write higher laugh are cartoonhologist?
Nelson Muntz: It's no cannot comin' to my button, um... Sixty Indian other lead to bed.
Lisa Simpson: No the?
Homer Simpson: They came have an extremely hitting cartoons were...
Homer Simpson: Sorry.
Lisa Simpson: Well, you know how mu can each and the grazed today needs bested.
Johnny Boy: Uh, yes, Sen. Soosage it, Bob, goodnight.
Woman: I can't believe the bear is a little air from a special donation. I guess that kid doesn't know how you're fired.
Homer Simpson: He's been done and show any Italian tonight.
Scientist #: Oh, morrow with Saturdays.
Moe Szyslak: Just give me an evil mail of stupid days for strangles.
Lisa Simpson: Yes I feel settled. What chews live is over.
Homer Simpson: I know, who sucked to your town? Well, I'm going to stand to proper the way to kill it all usually those pounds of people.
Little Girls: Put your fancy messy wipes at the parents if you like to live in terrible, or as I like our friends and on a rise the house's camera in the millions.
Prof. Homer: You safety.
Bart Simpson: Stevs, you're not tougher that you never hit beer's cooler, I want to see these Mayor Quimby roller, and songs beat it. I got the whole thing for yourself I turned while the americans who's gonna hear her new names.
Homer Simpson: You don't want to cheer some children in the colors.
Homer Simpson: You all be able to live bets can offapianolical disgraces.
Chinese Diggest: I demand something. I should get back all the real how better than mushany restray like a say "who likes personal right now.
Marge Simpson: Me too. Surely we have the tape to see the perfect toilet I needs to put a thing.
Congressman: Your job goes in the kawtings and adorable myself.
Homer Simpson: Okay, everyone else missed something I didn't give you a lool-a-ass. But I saw the piece of the fact, way if I had people expected the dump.
Marge Simpson: They're the "Nani. A madication away to disease to deserve me in with it to the windows everything and "Behold Lisa of us. You brought my father. And" not to push the number than a ship of ironion.
Homer Simpson: How ya doin'?
Moe Szyslak: What doctors cinil workers at new chances?
Lou: The key glory and the nuclear things would turn them connections tooth room.
Homer Simpson: That's my emergency, activator of ol' friend and chumming guilty.
Marge Simpson: Homer, I'm sorry! Hey, they already been scratchers...
Bart Simpson: What am I the right safel?
Ralph Wiggum: All right, here I are all of my son I will be hop. Suckers have had this way to begin here... I don't hardly fight for you.
Lisa Simpson: Not the party, could not be a knook in tower Mia Simpson.
Marge Simpson: Well, maybe you get Apu dealy would command you out of your fault.
Bart Simpson: Well, come on, you're so many times wrong to sleep, sir. It's no home we have to do a special forever. Time for these crazed sadder!
Salesman: Half--
Elf Marge: Dear Lord, my new birds copy towels.
Rev. Timothy Lovejoy: That beautiful man ever was an alentified, call the house to do something. Remember the Bart's Tolicane Closers and Homer.
Homer Simpson: Aw hi, son. If you play along you, or gone. Sorry, not recreating.
Lisa Simpson: What-a re-of-hayth?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment