Giter Site home page Giter Site logo

generate_tv_scripts_with_lstm's Introduction

Generate TV Scripts with LSTM

Summary

In this project, we will generate our own Simpsons TV scripts using RNNs, specifically an LSTM in TensorFlow. The neural network we build will generate a new TV script for a scene at Moe's Tavern.

Data

We will be using part of the Simpsons dataset of scripts from 27 seasons. We will be using a subset of the original dataset. It consists of only the scenes in Moe's Tavern.

Preprocessing Functions

def create_lookup_tables(text):
    """
    Create lookup tables for vocabulary
    :param text: The text of tv scripts split into words
    :return: A tuple of dicts (vocab_to_int, int_to_vocab)
    """
    # Narrow text down to unique words
    vocab = sorted(set(text))
    vocab_to_int = {word: ii for ii, word in enumerate(vocab)}
    int_to_vocab = dict(enumerate(vocab))
    return (vocab_to_int, int_to_vocab)

Created two dictionaries to go from words to ids and from ids to words. Next created another dictionary to help with tokenizing punctuation.

Choose Word

def pick_word(probabilities, int_to_vocab):
    """
    Pick the next word in the generated text
    :param probabilities: Probabilites of the next word
    :param int_to_vocab: Dictionary of word ids as the keys and words as the values
    :return: String of the predicted word
    """
    # If I want to return only the highest probability word, I can use idx = np.argmax(probabilities)
    idx = np.random.choice(len(int_to_vocab), p=probabilities)
    word = int_to_vocab[idx]
    return word

We'll select the next word using the softmax probabilities for each word.

Results

We trained on less than a megabyte of text and now have a sample script! For better results, we could use the broader Simpsons dataset.

generate_tv_scripts_with_lstm's People

Contributors

chrispmaag avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.