Skip to main content

A small example package

Project description

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, setSeed = 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abdoTheBest-1.0.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

abdoTheBest-1.0.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file abdoTheBest-1.0.0.tar.gz.

File metadata

  • Download URL: abdoTheBest-1.0.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for abdoTheBest-1.0.0.tar.gz
Algorithm Hash digest
SHA256 09045c6090bfe1b1e4b4fa4a309a973500ef64637c63e0d0d1b460671b267613
MD5 0dd86edb8f36368eed6a1ce29f19f883
BLAKE2b-256 55f3d948dfe7af193ea36a74b27f94c2c6d0490a6573a833982e13f3c207df03

See more details on using hashes here.

File details

Details for the file abdoTheBest-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: abdoTheBest-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for abdoTheBest-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3d0cb2b6cabf9945b303ffdedc05bc3ba9541e7f0892042a8d7c1c43be15cf
MD5 f4df8dbdc2fadc6b3329f780d7a572dd
BLAKE2b-256 96bc7c9735f4517e0ea73cfbe12c107398ae94742254822ba53bf5462a20d167

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page