Skip to main content

Downloads Image contributions welcome

nn_builder

nn_builder lets you build neural networks without boilerplate code. You specify the type of network you want and it builds it.

Install

pip install nn_builder

Support

Network Type NN CNN RNN
PyTorch ✔️ ✔️ ✔️
TensorFlow 2.0 ✔️ ✔️ ✔️

Examples

On the left is how you can create the PyTorch neural network on the right in only 1 line of code using nn_builder:

Screenshot

Similarly for TensorFlow on the left is how you can create the CNN on the right in only 1 line of code using nn_builder:

Screenshot

Usage

See this colab notebook for lots of examples of how to use the module. 3 types of PyTorch and TensorFlow network are currently supported: NN, CNN and RNN. Each network takes the following arguments:

Field Description Default
input_dim Dimension of the input into the network. See below for more detail. Not needed for Tensorflow. N/A
layers_info List to indicate the layers of the network you want. Exact requirements depend on network type, see below for more detail N/A
output_activation String to indicate the activation function you want the output to go through. Provide a list of strings if you want multiple output heads No activation
hidden_activations String or list of string to indicate the activations you want used on the output of hidden layers (not including the output layer), default is ReLU and for example "tanh" would have tanh applied on all hidden layer activations ReLU after every hidden layer
dropout Float to indicate what dropout probability you want applied after each hidden layer 0
initialiser String to indicate which initialiser you want used to initialise all the parameters PyTorch & TF Default
batch_norm Boolean to indicate whether you want batch norm applied to the output of every hidden layer False
columns of_data_to_be_embedded List to indicate the column numbers of the data that you want to be put through an embedding layer before being fed through the hidden layers of the network No embeddings
embedding_dimensions If you have categorical variables you want embedded before flowing through the network then you specify the embedding dimensions here with a list of the form: [ [embedding_input_dim_1, embedding_output_dim_1], [embedding_input_dim_2, embedding_output_dim_2] ...] No embeddings
y_range Tuple of float or integers of the form (y_lower, y_upper) indicating the range you want to restrict the output values to in regression tasks No range
random_seed Integer to indicate the random seed you want to use 0
return_final_seq_only Only needed for RNN. Boolean to indicate whether you only want to return the output for the final timestep (True) or if you want to return the output for all timesteps (False) True

Each network type has slightly different requirements for input_dim and layers_info as explained below:


1. NN
  • input_dim: # Features in PyTorch, not needed for TensorFlow
  • layers_info: List of integers to indicate number of hidden units you want per linear layer.
  • For example:
from nn_builder.pytorch.NN import NN   
model = NN(input_dim=5, layers_info=[10, 10, 1], output_activation=None, hidden_activations="relu", 
           dropout=0.0, initialiser="xavier", batch_norm=False)            

2. CNN
  • input_dim: (# Channels, Height, Width) in PyTorch, not needed for TensorFlow
  • layers_info: We expect the field layers_info to be a list of lists indicating the size and type of layers that you want. Each layer in a CNN can be one of these 4 forms:
    • ["conv", channels, kernel size, stride, padding]
    • ["maxpool", kernel size, stride, padding]
    • ["avgpool", kernel size, stride, padding]
    • ["linear", units]
  • For a PyTorch network kernel size, stride, padding and units must be integers. For TensorFlow they must all be integers except for padding which must be one of {“valid”, “same”}
  • For example:
from nn_builder.pytorch.CNN import CNN   
model = CNN(input_dim=(3, 64, 64), 
            layers_info=[["conv", 32, 3, 1, 0], ["maxpool", 2, 2, 0], 
                         ["conv", 64, 3, 1, 2], ["avgpool", 2, 2, 0], 
                         ["linear", 10]],
            hidden_activations="relu", output_activation="softmax", dropout=0.0,
            initialiser="xavier", batch_norm=True)

3. RNN
  • input_dim: # Features in PyTorch, not needed for TensorFlow
  • layers_info: We expect the field layers_info to be a list of lists indicating the size and type of layers that you want. Each layer in a CNN can be one of these 4 forms:
    • ["lstm", units]
    • ["gru", units]
    • ["linear", units]
  • For example:
from nn_builder.pytorch.CNN import CNN   
model = RNN(input_dim=5, layers_info=[["gru", 50], ["lstm", 10], ["linear", 2]],
            hidden_activations="relu", output_activation="softmax", 
            batch_norm=False, dropout=0.0, initialiser="xavier")

Contributing

Together we can make something that is useful for thousands of people. Anyone is very welcome to contribute via a pull request. Please see the issues page for ideas on the best areas to contribute to and try to:

  1. Add tests to the tests folder that cover any code you write
  2. Write comments for every function
  3. Create a colab notebook demonstrating how any extra functionality you created works

Metadata

Release files for nn-builder 1.0.5

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

Source distribution (sdist)

Source distribution for nn-builder 1.0.5
File Size Uploaded Provenance Actions
nn_builder-1.0.5.tar.gz 16.9 kB Without provenance Details for nn_builder-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nn-builder 1.0.5
File Interpreter ABI Platform Actions
nn_builder-1.0.5-py3-none-any.whl Python 3 none any Details for nn_builder-1.0.5-py3-none-any.whl

Total release size: 44.7 kB

Release files / nn_builder-1.0.5.tar.gz

Download URL nn_builder-1.0.5.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
afde63395976d19175a578fa3b6b7b9ac6d3fca3c245f2d8466b331e4e064dd6
BLAKE2b-256 checksum
How to use checksums
6f2e4db9d142ad6c39a91503bdde1bb1f0d8ebe796dc4de34dabc335de0a7781
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

Release files / nn_builder-1.0.5-py3-none-any.whl

Download URL nn_builder-1.0.5-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e5e57fe215a5a37b59ff34a0ed3c60c2d003478e22566603fd2f9461e1f4ed5
BLAKE2b-256 checksum
How to use checksums
2020521e8a8083e158e4f5cc028e1fb472fa85a5eaeafb08cddcec6b52af9d33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

Security for nn-builder 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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