Code Monkey home page Code Monkey logo

char-rnn-gluon's Introduction

Char-RNN-Gluon

使用字符级别的RNN进行文本生成,使用MXNet-Gluon框架。PyTorch实现

Requirements

  • MXNet 0.11.1
  • numpy

Basic Usage

如果希望训练网络,使用如下的代码

python main.py \
--state train \
--txt './data/poetry.txt' \ # 训练用的txt文本
--batch 128  \ # batch_size
--epoch 1000 \ 
--len 100 \ # 输入RNN的序列长度
--max_vocab 5000 \ # 最大的字符数量
--embed 512 \ # 词向量的维度
--hidden 512 \ # 网络的输出维度
--n_layer 2 \ # RNN的层数
--dropout 0.5

如果希望使用训练好的网络进行文本生成,使用下面的代码

python main.py \
--state eval \
--begin '' \ # 生成文本的开始,可以是一个字符,也可以一段话
--pred_len 100 \ # 希望生成文本的长度
--checkpoint './checkpoint/model_100.pth' # 读取训练模型的位置

Result

如果使用古诗的数据集进行训练,可以得到下面的结果

我来钱庙复知世依。似我心苦难归久,相须莱共游来愁报远。近王只内蓉者征衣同处,规廷去岂无知径草木飘。
独爱滞大道愚促促榴才也,工韵诚千春和。风清月道路白暇。甫相送远,航冲空弄游残风催殊娟寸年。
我独心。行辛秀头为鸦石尘,那里非洛阳。学不境幽,出佳当禅最命壁戎松栖落。
藤二蛙归唯去尺续白宗熟劳熟无相世雁部,渔人独踟楼禅。
云月同秋草文翩家,南归宽同梢惆。
看取韵抱对,能闲掩眠妇卖眠士云坐。

如果使用周杰伦的歌词作为训练集,可以得到下面的结果

我们的爱
持纵的微银 
我路茫未望
象对躲睡被仁消 整虹伪沙
乡月裂续武深面到
身壁许达道 
用移照叫生

char-rnn-gluon's People

Contributors

l1aoxingyu avatar

Watchers

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