Giter Club home page Giter Club logo

char-rnn-tf's Introduction

Character-level language modelling with RNN

A RNN character-level language model, implemented with Tensorflow in Python. This blog is a great introduction to RNN character-level language model. Here is a torch implementation of the same model.

Dependency

  • python2.6+
  • numpy
  • tensorflow 0.7+

Usage

Small Shakespeare Data

The data is provided in this repository.

Training

Train the model with default hyperparameters:

python train.py

Or, train with self-specified hyperparameters:

python train.py --model gru --batch_size 60 --hidden_size 100 --init_lr 0.05 --num_epochs 25 --dropout 0.5

By default, a 2-layer LSTM model will be used, and will be unrolled for 50 steps during gradient descent.

For a complete list of parameters, please consult model.py and train.py.

Sampling

Sampling is the process to generate sampled text from a trained model. To perform sampling:

python sample.py --max_length 1000

Wikipedia Article Samples

The data is from wikipedia dump, and is cleaned by myself.

To train the model on the sample wikipedia article data, we need slightly different parameters:

python train.py --data_dir data/wikipedia/ --data_file enwiki-articles-sample.xml --vocab_size 203 --hidden_size 256 --batch_size 128

To sample from the trained model, we need to set the model to the same parameter setting:

python sample.py --data_dir data/wikipedia/ --vocab_size 203 --hidden_size 256 --batch_size 128 --start_with "<ref" --max_length 2000

Example Sampling Output:

After training on the data for 30 epochs, the models generate the following sampling results:

Shakespeare

ROMEO:
Saint me: disperature so none.

CAMILLO:
Al you so beating they amen thy truthfring man
And far own fear.
Go, my leave revet you, live me noble from juster!
I have that give these men joy as are in defubject.

HENRY PERCY:
That he all ask'd court? who, being costing. Stather's corrant more
with reputy to a vastory soft unherity.
Our with kins from his na talk not! is Busfort:
From death's lady! hath kneal,-trains hot peace,
Be love the kinglies.

PETER:
Who hath Garuems were, but the birth,
Than good lord!

Wikipedia

[[Category:Tideranus]]
[[Category:Scales at the 0940 in Portigo]]
[[Category:Pubself in sponsors for, for handled the based trainager|Fighter Ulmation Court of Couge]]</text>
      <sha1>bjcn02zyb9hzgps22fbrvqfmiwzdy27l</sha1>
    </revision>
  </page>
  <page>
    <title>Bandelleha Director Commons of Pat Rubyaportfland</title>
    <ns>0</ns>
    <id>7797276</id>
    <revision>
      <id>647031804</id>
      <parentid>656267067</parentid>
      <timestamp>2013-07-09T14:59:11Z</timestamp>
      <contributor>
        <username>Revilities</username>
        <id>16562568</id>
      </contributor>
      <minor />
      <comment>[[Wikipedia:Wikidata|Wikidata|Wikidata]] leaded delined to 11 &ndacre discussionship groud in the [[Barlomawa]], and wons, Marino Regionals, Source. ([[Green]].

We can see that the RNN actually learns to generate all the indentations and learns to open and close XML tags and brackets in most cases!

License

MIT

char-rnn-tf's People

Contributors

yuhaozhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jqlts1

char-rnn-tf's Issues

Deep Convolutional Network for Handwritten Chinese Character Recognition

hi,
I am so appreciated with your great job in paper "Deep Convolutional Network for Handwritten Chinese Character Recognition"
but when i write a tensorflow code according to the architecture M7-1 in your paper. It seems not converged. I have try anything i can do such learning rate, Optimizer and so on.

training process

training start!
epoch: 0 db_num: 100/10000 avg_train_loss: 8.3131493187 avg_val_loss:8.23082val_acc:0.0
epoch: 0 db_num: 200/10000 avg_train_loss: 8.27199922085 avg_val_loss:8.23097val_acc:0.0005
epoch: 0 db_num: 300/10000 avg_train_loss: 8.25830560048 avg_val_loss:8.2306val_acc:0.0
epoch: 0 db_num: 400/10000 avg_train_loss: 8.25148080826 avg_val_loss:8.22987val_acc:0.0
epoch: 0 db_num: 500/10000 avg_train_loss: 8.24735763741 avg_val_loss:8.2292val_acc:0.0005
epoch: 0 db_num: 600/10000 avg_train_loss: 8.2446211497 avg_val_loss:8.22861val_acc:0.0
epoch: 0 db_num: 700/10000 avg_train_loss: 8.24270825931 avg_val_loss:8.228val_acc:0.001
epoch: 0 db_num: 800/10000 avg_train_loss: 8.24126857758 avg_val_loss:8.22774val_acc:0.0
epoch: 0 db_num: 900/10000 avg_train_loss: 8.24019092454 avg_val_loss:8.22709val_acc:0.0
epoch: 0 db_num: 1000/10000 avg_train_loss: 8.23933010769 avg_val_loss:8.22652val_acc:0.0
epoch: 0 db_num: 1100/10000 avg_train_loss: 8.23863611308 avg_val_loss:8.22713val_acc:0.0
epoch: 0 db_num: 1200/10000 avg_train_loss: 8.23803685904 avg_val_loss:8.22812val_acc:0.0005
epoch: 0 db_num: 1300/10000 avg_train_loss: 8.23755813965 avg_val_loss:8.22869val_acc:0.0005
epoch: 0 db_num: 1400/10000 avg_train_loss: 8.23713573796 avg_val_loss:8.22927val_acc:0.0
epoch: 0 db_num: 1500/10000 avg_train_loss: 8.23680315081 avg_val_loss:8.23023val_acc:0.0
epoch: 0 db_num: 1600/10000 avg_train_loss: 8.23646358132 avg_val_loss:8.23099val_acc:0.0
epoch: 0 db_num: 1700/10000 avg_train_loss: 8.23617212576 avg_val_loss:8.23184val_acc:0.0
epoch: 0 db_num: 1800/10000 avg_train_loss: 8.23592109203 avg_val_loss:8.23268val_acc:0.0

Can you share your code?
thanks so much.

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.