Giter Site home page Giter Site logo

qile-paul-chen / poetry-seq2seq Goto Github PK

View Code? Open in Web Editor NEW

This project forked from disiok/poetry-seq2seq

0.0 2.0 0.0 79.16 MB

Chinese Poetry Generation

License: MIT License

Python 10.92% Jupyter Notebook 85.41% Makefile 0.03% JavaScript 1.44% CSS 0.18% HTML 2.01% Shell 0.01%

poetry-seq2seq's Introduction

Chinese Poetry Generation

This project aims to implement and improve upon the classical Chinese poetry generation system proposed in "Chinese Poetry Generation with Planning based Neural Network".

Generated Sample

Sample generated Chinese poetry

Dependencies

Python 2.7
TensorFlow 1.2.1
Jieba 0.38
Gensim 2.0.0
pypinyin 0.23

Features

Network:

  • Bidirectional encoder
  • Attention decoder

Training and Predicting:

  • Alignment boosted word2vec
  • Data loading mode: only keywords (no preceding sentences)
  • Data loading mode: reversed
  • Data loading mode: aligned
  • Training mode: ground truth
  • Training mode: scheduled sampling
  • Predicting mode: greedy
  • Predicting mode: sampling
  • Predicting mode: beam search

Refinement:

  • Output refiner
  • Reinforcement learning tuner
  • Iterative polishing

Evaluation:

  • Evaluation: rhyming
  • Evaluation: tonal structure
  • Evaluation: alignment score
  • Evaluation: BLEU score

Project Structure

Data
data: directory for raw data, processed data, pre-processed starterkit data, and generated poetry samples
model: directory for saved neural network models
log: directory for training logs
notebooks: directory for exploratory/experimental IPython notebooks
training_scripts: directory for sample scripts used for training several basic models

Code
model.py: graph definition
train.py: training logic
predict.py: prediction logic
plan.py: keyword planning logic
main.py: user interaction program

Data Processing

To prepare training data:

python data_utils.py

Detail
This scrip does the following in order:

  1. Parse corpus
  2. Build vocab
  3. Filter quatrains
  4. Count words
  5. Rank words
  6. Generate training data

Note
The TextRank algorithm may take many hours to run.
Instead, you can choose to interrupt the iterations and stop it early,
when the progress shown in the terminal has remained stationary for a long time.

Then, to generate the word embedding:

python word2vec.py

Alternative
As an alternative, we have also provided pre-processed data in the data/starterkit directory
You may simply perform cp data/starterkit/* data/processed to skip the data processing step

Training

To train the default model:

python train.py

To view the full list of configurable training parameters:

python train.py -h

Note
Thus you should almost always train a new model after modifying any of the parameters.
Models are by default saved to model/. To train a new model, you may either remove the existing model from model/
or specify a new model path during training with python train.py --model_dir :new_model:dir:

Generating

To start the user interation program:

python main.py

Similarly, to view the full list of configurable predicting parameters:

python main.py -h

Note
The program currently does not check that predication parameters matches corresponding training parameters.
User has to ensure, in particular, the data loading modes correspond with the ones used during traing.
(e.g. If training data is reversed and aligned, then prediction input should also be reversed and aligned.
Otherwise, results may range from subtle differences in output to total crash.

Evaluating

To generate sample poems for evaluation:

python generate_samples.py

Detail
This script by default randomly samples 4000 poems from the training data and saves them as human poems. Then it uses entire poems as inputs to the planner, to create keywords for the predictor. The predicted poems are saved as machine poems.

To evaluate the generated poems:

python evaluate.py

Further Reading

Auxiliary

  1. "Scheduled Sampling for Sequence Prediction with Recurrent Neural Networks"
  2. "Sequence-to-Sequence Learning as Beam-Search Optimization"
  3. "Tuning Recurrent Neural Networks with Reinforcement Learning"
  4. "Deep Reinforcement Learning for Dialogue Generation"

Poetry Generation

  1. May 10, 2017: "Flexible and Creative Chinese Poetry Generation Using Neural Memory"
  2. Dec 7, 2016: "Chinese Poetry Generation with Planning based Neural Network"
  3. June 19, 2016: "Can Machine Generate Traditional Chinese Poetry? A Feigenbaum Test"

Acknowledgement

  1. The data processing source code is based on DevinZ1993's implementation.
  2. The neural network implementation is inspired by JayParks's work.

poetry-seq2seq's People

Contributors

disiok avatar vvcepheia avatar devinz1993 avatar

Watchers

James Cloos avatar paper2code - bot 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.