Giter Site home page Giter Site logo

rileynwong / pytorch-char-rnn Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 3.66 MB

PyTorch implementation of charRNN neural network

Home Page: https://www.rileynwong.com/blog/2019/4/24/implementing-char-rnn-from-scratch-in-pytorch-and-generating-fake-book-titles

Python 26.72% Jupyter Notebook 73.28%
pytorch pytorch-implementation char-rnn character-rnn language-model recurrent-neural-networks neural-networks recurrent-neural-network neural-network book-titles

pytorch-char-rnn's Introduction

PyTorch Char-RNN

PyTorch implementation of a character-level recurrent neural network. See accompanying blog post.

Includes pretrained models for generating:

  • fake book titles in different genres
  • first names in different languages
  • constellation names in English and Latin

Examples

Book titles

Possible categories in the pretrained model include: Adult_Fiction, Erotica, Mystery, Romance, Autobiography, Fantasy, New_Adult, Science_Fiction, Biography, Fiction, Nonfiction, Sequential_Art, Childrens, Historical, Novels, Short_Stories, Christian_Fiction, History, Paranormal, Thriller, Classics, Horror, Philosophy, Young_Adult, Contemporary, Humor, Poetry, Dark, Lgbt, Religion

Heart in the Dark (Romance)

Book of the Dark (Fantasy) 

Bed Store (Young Adult)

Growing Me (New Adult)
Me the Bean (New Adult) 

King of the Dark (Erotica)
Your Mind (Erotica)

Red Story (Mystery) 

Be the Life (Biography)

First names

Possible categories in the pretrained model include: Arabic, Chinese, Czech, Dutch, English, French, German, Greek, Irish, Italian, Japanese, Korean, Polish, Portuguese, Russian, Scottish, Spanish, Vietnamese

Russian:

Rovakov
Uanten
Shantovov

Chinese:

Chan
Hang
Iun

Constellations

English:

orogane
quale
rowans
serpent
kelescop

Latin:

bearis
corac
serpens
xer
zeriscase

File Overview

  • generate_books.py: Train/generate fake book titles.
  • generate_names.py: Train/generate fake first names.
  • generate_constellations.py: Train/generate fake constellation names.
  • csv_to_txt.ipynb: Notebook to convert
  • models/: Saved models.
  • data/: Training data sets as text files.

Setup

All you really need is PyTorch.

Usage

At the bottom of each script, the function call samples(CATEGORY, START_LETTERS) can be modified for whatever category/starting letters you want.

$ python generate_names.py:

  • samples('Russian', 'RUS)

$ python generate_books.py:

  • samples('Fiction', 'abcdefghijklmnopqrstuvwxyz')

$ python generate_constellations.py

  • samples('latin', 'abcdefghijklmnopqrstuvwxyz')

Training your own

Set line 174 and 175 to:

rnn = RNN(n_letters, 128, n_letters)
# rnn = torch.load('models/book_titles.pt')

Uncomment out this part in the script:

print('Training model...')
for iter in range(1, n_iters + 1):
    output, loss = train(*random_training_example())
    total_loss += loss

    if iter % print_every == 0:
        print('%s (%d %d%%) %.4f' % (timeSince(start), iter, iter / n_iters * 100, loss))

### Save model after training
torch.save(rnn, 'language_names.pt')

You can also set the training data directory on line 31: data_glob = 'data/names/*.txt' to data_glob = 'data/your_dir/*.txt'

and setting each category of text within its own .txt file within the data/your_dir/ directory.

Generating your own

If you just want to generate samples, you can comment out the training snippet and set the network to load the pretrained model. i.e. Set line 174 and 175 to:

# rnn = RNN(n_letters, 128, n_letters)
rnn = torch.load('models/book_titles.pt')

and re-run the script.

Credits

pytorch-char-rnn's People

Stargazers

 avatar  avatar

Watchers

 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.