High level interface for text applications using PyTroch RNN's.
Project description
GeNN
GeNN (generative neural networks) is a high-level interface for text applications using PyTorch RNN's.
Features
- 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.
- Architectures and customization:
- GPT-2 with small, medium, and large variants.
- LSTM and GRU, with variable size.
- Variable number of layers and batches.
- Dropout.
- 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.
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
from genn import Preprocessing, LSTMGenerator, GPT2
#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))
#GPT-2 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))
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
abdoTheBest-0.9.tar.gz
(13.2 kB
view hashes)
Built Distribution
abdoTheBest-0.9-py3-none-any.whl
(17.4 kB
view hashes)
Close
Hashes for abdoTheBest-0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a1cc6b3a017fb7f721b60fc5d31b93ba395c9e4bacd257c0aeaccba3f84f4aa |
|
MD5 | ded77b4b9f2bb9a63b507715f8d90591 |
|
BLAKE2b-256 | 2968dda7191bf4b6f2c747c9cc00f9901aefc70a9f21a257b9ef40ed7e530a50 |