Coder Social home page Coder Social logo

xeddmc / wavenet-for-poem-generation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jhave/wavenet-for-poem-generation

0.0 3.0 0.0 179.19 MB

a port of the Wavenet algorithm to generate poems (using Samuel Graván's @Zeta36 code).

Python 99.00% HTML 0.07% Shell 0.93%

wavenet-for-poem-generation's Introduction

A TensorFlow implementation of DeepMind's WaveNet paper for POEM generation.

Blog post describing process and resultant poems:
http://bdp.glia.ca/wavenet-for-poem-generation-preliminary-results

Code is based almost entirely on Samuel Graván's (Zeta36) implementation of tensorflow-tex-wavenet https://github.com/Zeta36/tensorflow-tex-wavenet.

Modified to allow for line breaks, identifiable generated txt files, and more flexible saving of models so that it is possible to capture fluctuations in the parameters.

Requirements

TensorFlow needs to be installed before running the training script. TensorFlow 0.10 and the current master version are supported.

Training the network

You can use any text (.txt) file.

In order to train the network, execute

python train.py --data_dir=data

to train the network, where data is a directory containing .txt files. This repo includes a txt source with 11k poems in data/pf The script will recursively collect all .txt files in the directory.

You can see documentation on each of the training settings by running

python train.py --help

You can find the configuration of the model parameters in wavenet_params.json. These need to stay the same between training and generation.

Here's an example training call that keeps all models with loss below 1.0:

python train_Oct13_Low1_keepALL.py --wavenet_params=wavenet_params_ORIG_dilations256_skipChannels2048.json  --data_dir=data/pf

If training fails at some point, or you simply want to restart add the following parameter (2016-10-15T20-25-20 is in this example the directory where the models are stored)

 --restore_from=./logdir/train/2016-10-15T20-25-20/

Generating text

You can use the generate.py script to generate poetry using a previously trained model.

Run

python generate.py --samples 16000 model.ckpt-1000

where model.ckpt-1000 needs to be a previously saved model. You can find these in the logdir. The --samples parameter specifies how many characters samples you would like to generate.

The generated POETRY is by default saved as a .txt file to the GENERATED folder named to reflect source folder and model number. The following examples will use the demo models in the repo to generate a .txt file saved to "GENERATED/demos_Model_#######.txt"

python generate_Oct13.py --samples 6000 --wavenet_params=wavenet_params_ORIG_dilations256_skipChannels2048.json ./logdir/train/demos/model.ckpt-33800
python generate_Oct13.py --samples 66000 --wavenet_params=wavenet_params_ORIG_dilations1024_skipChannels1024.json /Users/jhave/Desktop/github/Wavenet-for-Poem-Generation/logdir/train/demos/model.ckpt-62324

Note: the wavenet_params values must be the same size as the training, or the generate code returns "InvalidArgumentError: Assign requires shapes of both tensors to match.""


Passing --save_every will save the file every n samples. I have used this to create a typewriter like effect where line after line appears in rapid succession. Has potential for performance.

python generate.py --save_every 100 --samples 1500 model.ckpt-1000

Fast generation is enabled by default. It uses the implementation from the Fast Wavenet repository. You can follow the link for an explanation of how it works. This reduces the time needed to generate samples to a few minutes.

To disable fast generation:

python generate.py --samples 1500 model.ckpt-1000 --fast_generation=false

(Note: As of Oct 16th, I have never disabled fast generation.)

wavenet-for-poem-generation's People

Contributors

jhave avatar

Watchers

James Cloos avatar B. Zach 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.