Git Product home page Git Product logo

text_generator's Introduction

RNN Text Generator

A recurrent neural network text generator, created using tensorflow. The project includes the files for a pre-trained text generator based on 'Alice in Wonderland,' and a dataset of around 800,000 tweets from July and August 2020 about the US presidential election.

Model Training

Each model is defined with a unique model name/ID, used to save all necessary files. When the dataset is read, a banned_chars.txt file can be used to filter certain characters from the dataset before training.

    # First define the model, which creates all directories.
    model = 'wonderland'
    generator = TextGenerator(model)

    # Read and encode the dataset (dataset location defaults to 'models/$MODEL$/data/dataset.txt')
    text = generator.read_data()
    generator.create_dataset(text, verbose=True)
    
    # Train the model.
    generator.train_model(30)

    # Generate text.
    random_seed = ''.join(random.choice(string.ascii_letters) for i in range(random.randint(5, 100)))
    generated_text = generator.generate_text(random_seed, max_chars=20)

Text Generation

All files needed for text generation are created during the dataset creation and training, and are saved in the data, obj and results files in the model's directory. These are:

  • weights.h5: RNN model weights.
  • model_info: Saves model info such as vocabulary, sequence length and batch size.
  • char2int.obj & int2char.obj: Dictionaries for converting characters to and from integers.

Text can then be generated using the generate_text() function.

Examples

Generating text from the 'wonderland' model:

Seed: rFsKZACTjOAGhFjJlYWCydvXnjmYHhuPRGAhqHUOMOczxmyAyFlvNaRCQffPEOtZv
Generated text:
e got to
in lyister! And I shall see if the next
witness! No, I'll set here! No, and do nit ear leftle golden that is I used to know. Let me
see: that it made of the glass---        OW could see's the little door!'
Seed: TtZkTtOoTaelMuRvxBBiaqmiNctcqUsAVzEToUvIr
Generated text:
goon seemer legs, you know. But do cats eat bats, I wonder what Lasity that I'm going
on she comy in lime till she'll be a presendy to seemed to be in the other
laws.

The hall, it I know she had got to things--y u inderstand will be ne time! And when I find a thing,' said the Caterpillar.

'I'm afraid I can't put it more than I am
now? That'll be a comfort, one way--near--Ho the way all store.

text_generator's People

Contributors

calluume avatar

Stargazers

 avatar

Watchers

 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.