Skip to content
Generate any kind of text with Character Embedding and RNN in pure Numpy
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
data
model-files
src
tests Add unit tests Jul 26, 2019
.gitignore Initial commit Jul 15, 2019
LICENSE
README.md
inference.py
requirements.txt
train.py

README.md

Generate Any Text

Generate any kind of text with character embedding and RNN in pure Numpy.

Note that this project is not optimized for performance. It is rather a reference implementation for many building blocks of neural networks.

Check this list to reach implemented elements.

Example Training

Clone the repository and change directory into it

git clone https://github.com/kirbiyik/generate-any-text
cd generate-any-text

This project has only 3 dependencies: Numpy for numeric computation, tqdm for progress bar and matplotlib for plotting. You probably already have these. Otherwise run command below.

pip install -r requirements.txt

Download the Trump speeches dataset

wget -P data/ https://github.com/ryanmcdermott/trump-speeches/blob/master/speeches.txt

Start training

python train.py -d data/speeches.txt 

See the other arguments.

Here is an example footage of training. It learns how to generate Trump-like tweets with a 3 minutes training in CPU.

Example Inference

Models will be saved under model-files unless explicitly specified.

python inference.py -m model-files/char_rnn_epoch3.pkl -s i

See the other arguments.

Elements

Click on any item to go to related line of code.

Testing

Run unit tests with

python tests/layers.py

Dataset

Trump speeches dataset is used for demonstration. Though it is possible to use any kind of text file. It does not require any special format. It learns what you feed!

Here is a resource for many free eBooks.

Acknowledgement

This work is heavily based on Stanford's CS 231n Assignments. I've implemented additional layers and features for the special needs of this problem.

You can’t perform that action at this time.