Skip to main content

GeNN

GitHub license

GeNN (generative neural networks) is a high-level interface for text applications using PyTorch RNN's.

Features

  1. Preprocessing:
    • Parsing txt, json, and csv files.
    • NLTK, regex and spacy tokenization support.
    • GloVe and fastText pretrained embeddings, with the ability to fine-tune for your data.
  2. Architectures and customization:
    • GPT2 with small, medium, and large variants.
    • LSTM and GRU, with variable size.
    • Variable number of layers and batches.
    • Dropout.
  3. Text generation:
    • Random seed sampling from the n first tokens in all instances, or the most frequent token.
    • Top-K sampling for next token prediction with variable K.
    • Nucleus sampling for next token prediction with variable probability threshold.
  4. Text Summarization:
    • All GPT2 variants can be trained to perform text summarization.

Getting started

How to install

pip install genn

Prerequisites

  • PyTorch 1.4.0
pip install torch==1.4.0
  • Pytorch Transformers
pip install pytorch_transformers
  • NumPy
pip install numpy
  • fastText
pip install fasttext

Use the package manager pip to install genn.

Usage

Text Generation:

RNNs (You can switch LSTMGenerator with GRUGenerator:
from genn import Preprocessing, LSTMGenerator, GRUGenerator
#LSTM example
ds = Preprocessing("data.txt")
gen = LSTMGenerator(ds, nLayers = 2,
                        batchSize = 16,
                        embSize = 64,
                        lstmSize = 16,
                        epochs = 20)
			
#Train the model
gen.run()

# Generate 5 new documents
print(gen.generate_document(5))
GPT2 Generator:
#GPT2 example
gen = GPT2("data.txt",
 	    taskToken = "Movie:",
	    epochs = 7,
	    variant = "medium")
#Train the model
gen.run()

#Generate 10 new documents
print(gen.generate_document(10))

Text Summarization:

GPT2 Summarizer:
#GPT2 Summarizer example
from genn import GPT2Summarizer
summ = GPT2Summarizer("data.txt",
			epochs=3,
			batch_size=8)

#Train the model
summ.run()

#Create 5 summaries of a source document
src_doc = "This is the source document to summarize"
print(summ.summarize_document(n=5, source = src_doc))

For more examples on how to use Preprocessing, please refer to this file.

For more examples on how to use LSTMGenerator and GRUGenerator, please refer to this file.

For more examples on how to use GPT2, please refer to this file.

For more examples on how to use GPT2Summarizer, please refer to this file.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Distributed under the MIT License. See LICENSE for more information.

Release files for genn 0.7.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genn 0.7.7
File Size Uploaded
genn-0.7.7.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for genn 0.7.7
File Interpreter ABI Platform
genn-0.7.7-py3-none-any.whl Python 3 none any Details

Total release size: 38.4 kB

Release files / genn-0.7.7.tar.gz

Download URL genn-0.7.7.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
452cb34f9cb1f2559984555dae94c487fe2afada1c203824bc6255f76ad286f6
BLAKE2b-256 checksum
How to use checksums
62ce65fc27c7a935109d81b2a69302d5677a22ebe22a062e6bc7b4a9f60dd85e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7

Release files / genn-0.7.7-py3-none-any.whl

Download URL genn-0.7.7-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36ed4959b1969db2c60c0b614523ae7194caacb3b7d5148725c16b0458e2b1cd
BLAKE2b-256 checksum
How to use checksums
dae5b4d8792d7e795dfa4639f84667184c01ac465ef36cac098931ea58316065
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7

Release history Release notifications | RSS feed

This release

0.7.7 This release

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page