by crazydonkey200

crazydonkey200 / tensorflow-char-rnn

Char-RNN implemented using TensorFlow.

426 Stars 285 Forks Last release: Not found MIT License 105 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


A TensorFlow implementation of Andrej Karpathy's Char-RNN, a character level language model using multilayer Recurrent Neural Network (RNN, LSTM or GRU). See his article The Unreasonable Effectiveness of Recurrent Neural Network to learn more about this model.



  • Python 2.7
  • TensorFlow >= 1.2

Follow the instructions on TensorFlow official website to install TensorFlow.


If the installation finishes with no error, quickly test your installation by running:

python train.py --data_file=data/tiny_shakespeare.txt --num_epochs=10 --test

This will train char-rnn on the first 1000 characters of the tiny shakespeare copus. The final train/valid/test perplexity should all be lower than 30.


  • train.py
    is the script for training.
  • sample.py
    is the script for sampling.
  • char_rnn_model.py
    implements the Char-RNN model.


To train on tiny shakespeare corpus (included in data/) with default settings (this might take a while):

python train.py --data_file=data/tiny_shakespeare.txt

All the output of this experiment will be saved in a folder (default to

, you can specify the folder name using

The experiment log will be printed to stdout by default. To direct the log to a file instead, use

(then it will be saved in

The output folder layout:

    ├── result.json             # results (best validation and test perplexity) and experiment parameters.
    ├── vocab.json              # vocabulary extracted from the data.
    ├── experiment_log.txt      # Your experiment log if you used --log_to_file in training.
    ├── tensorboard_log         # Folder containing Logs for Tensorboard visualization.
    ├── best_model              # Folder containing saved best model (based on validation set perplexity)
    ├── saved_model             # Folder containing saved latest models (for continuing training).


assume the data file is using utf-8 encoding by default, use
to specify the encoding if your data file cannot be decoded using utf-8.


To sample from the best model of an experiment (with a given starttext and length): ```bash python sample.py --initdir=your-output-folder --start_text="The meaning of life is" --length=100 ```


To use Tensorboard (a visualization tool in TensorFlow) to visualize the learning (the "events" tab) and the computation graph (the "graph" tab).

First run:

tensorboard --logdir=your-output-folder/tensorboard_log

Then navigate your browser to http://localhost:6006 to view. You can also specify the port using


Continuing an experiment

To continue a finished or interrupted experiment, run:

python train.py --data_file=your-data-file --init_dir=your-output-folder

Hyperparameter tuning

provides a list of hyperparameters you can tune.

To see the list of all hyperparameters, run:

python train.py --help

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.