wenhaofang / RNNDemo

Some demo RNN(Recurrent Neural Network) models implemented with pytorch, including RNN, LSTM, GRU.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RNN Demo

This repository includes some demo RNN(Recurrent Neural Network) models.

Note: The project refers to 动手学深度学习


Datasets:

  • dataset1: JayChou Lyrics

Models

  • model0: LanguageModel
    • model1: RNNCell
    • model2: LSTMCell
    • model3: GRUCell

Unit Test

  • for loader
# loader0: JayChou Lyrics
PYTHONPATH=. python loaders/loader0.py
  • for module
# module1: RNNCell
PYTHONPATH=. python modules/module1.py
# module2: LSTMCell
PYTHONPATH=. python modules/module2.py
# module3: GRUCell
PYTHONPATH=. python modules/module3.py
# module0: LanguageModel using RNNCell
PYTHONPATH=. python modules/module0.py --rnn_type rnn
# module0: LanguageModel using LSTMCell
PYTHONPATH=. python modules/module0.py --rnn_type lstm
# module0: LanguageModel using GRUCell
PYTHONPATH=. python modules/module0.py --rnn_type gru

Main Process

  • for train
PYTHONPATH=. python main.py --mode train
  • for predict
PYTHONPATH=. python main.py --mode predict

You can change the config either in the command line or in the file utils/parser.py

Here are the examples for each module:

# rnn train
PYTHONPATH=. python main.py \
    --mode train \
    --name rnn \
    --rnn_type rnn
# rnn predict
PYTHONPATH=. python main.py \
    --mode predict \
    --name rnn \
    --rnn_type rnn \
    --epoch 250 \
    --prefix 离开
# lstm train
PYTHONPATH=. python main.py \
    --mode train \
    --name lstm \
    --rnn_type lstm
# lstm predict
PYTHONPATH=. python main.py \
    --mode predict \
    --name lstm \
    --rnn_type lstm \
    --epoch 250 \
    --prefix 离开
# gru train
PYTHONPATH=. python main.py \
    --mode train \
    --name gru \
    --rnn_type gru
# gru predict
PYTHONPATH=. python main.py \
    --mode predict \
    --name gru \
    --rnn_type gru \
    --epoch 250 \
    --prefix 离开

Note: You can replace the data files in the data directory to train the model you want.

About

Some demo RNN(Recurrent Neural Network) models implemented with pytorch, including RNN, LSTM, GRU.


Languages

Language:Python 100.0%