项目作者: AleksTk

项目描述 :
Tensorflow implementation of a lstm-based character-level language model.
高级语言: Python
项目地址: git://github.com/AleksTk/rnn-char-lm.git
创建时间: 2017-10-08T20:39:17Z
项目社区:https://github.com/AleksTk/rnn-char-lm

开源协议:MIT License

下载


LSTM-based Character-level Language Model

Tensorflow implementation of a lstm-based character-level language model.
Given a list of items of interest, such as baby names or place names,
the model learns to reproduce text alike.

Usage

NB! For better performance, run this code on GPU.

Model Training

$ python train.py [options]

  1. Options:
  2. -h, --help show this help message and exit
  3. -t TRAIN, --train=TRAIN
  4. Train set location
  5. -m MODEL_DIR, --model_dir=MODEL_DIR
  6. Directory to store trained model.
  7. -o OPTIMIZER, --optimizer=OPTIMIZER
  8. Objective function optimiser ('rmsprop', 'adam' or
  9. 'gd' for gradient descent)
  10. -n NUM_EPOCHS, --num_epochs=NUM_EPOCHS
  11. Number of passes over training dataset
  12. -b BATCH_SIZE, --batch_size=BATCH_SIZE
  13. Batch size
  14. -e EMBEDDING_SIZE, --embedding_size=EMBEDDING_SIZE
  15. Character embedding size
  16. -r HIDDEN_SIZE, --hidden_size=HIDDEN_SIZE
  17. Rnn hidden layer size
  18. -l LEARNING_RATE, --learning_rate=LEARNING_RATE
  19. Initial learning rate
  20. -d DECAY_RATE, --decay_rate=DECAY_RATE
  21. Learning rate decay
  22. -D DROPOUT, --dropout=DROPOUT
  23. Dropout on the LSTM output (0 = no dropout)
  24. -L LOG_STEP, --log_step=LOG_STEP
  25. Print progress after n batches are processed.

For example, to train a model using data data/uk_towns.txt with 10 epochs and 0.5 dropout on outputs, run

  1. $ python train.py -t data/uk_towns.txt -m uk_towns -n 10 -D 0.5
  2. +------------------+------------------+------------------+----------------------------------------------------------------------------------+
  3. | epoch | train-loss | train-accuracy | examples |
  4. |------------------+------------------+------------------+----------------------------------------------------------------------------------|
  5. | 0 | 4.419108 | 0.013193 | T2qCf³B-0w,gNƒBLTaƒmy2oj, PGcn')PjjpXÃL3Y€K,X,fÂfi&N&)9IFKƒZwx0Ws²xRkA OnB,)... |
  6. | 0 | 4.318801 | 0.120107 | ArxGCG³eVaVAwweln,WHgqfMYCh5hk-&YâeOeoeaha,o7º.€p- ^ox3vade_n,6DVX¹Mg63caVkºa... |
  7. ...
  8. | 9 | 1.928021 | 0.429141 | Bintstone Chorpe,Llanfinabh,Saxtingham,Julsey,Babgeich,Pontforsha,Miltnow End... |
  9. | 9 | 1.943015 | 0.427479 | Manton End,Stenhall,Nydside,Nettington Meithworrie,Winshall,Rosswood,Kil Mait... |
  10. | 9 | 1.970449 | 0.419188 | Rhede,Eccoor,Crowton,Nont Heaed,Faven's Hill,Cufkerton,Beckkyldworth,Littling... |

Generating text

$ python generate.py [options]

  1. Options:
  2. -h, --help show this help message and exit
  3. -m MODEL_DIR, --model_dir=MODEL_DIR
  4. Model directory
  5. -t TEMPERATURE, --temperature=TEMPERATURE
  6. Temperature (0 > t <= 1.0). Large temperature implies
  7. more randomness.
  8. -n NUM_WORDS, --num_words=NUM_WORDS
  9. Number of items to generate
  10. -p PREFIX, --prefix=PREFIX
  11. Word prefix

For example, to generate 5 items with temperature 1 using pre-trained model uk_towns/epoch9, run

  1. $ python generate.py -m uk_towns/epoch9 -t 1 -n 5
  2. Heuston
  3. Wallboty
  4. Headbernis
  5. Old Lane
  6. Daive

Requirements

  1. python 3.4
  2. tensorflow 1.2.1

Install

  1. pip install -r requirements.txt

License

MIT