Package: nn-builder
nn_builder lets you build neural networks without boilerplate code. You specify the type of network you want and it builds it.Installpip install nn_builderSupportNetwork TypeNNCNNRNNPyTorch:heavy_check_mark::heavy_check_mark::heavy_check_mark:TensorFlow 2.0:heavy_check_mark::heavy_check_mark::heavy_check_mark:ExamplesOn the left is how you can create the PyTorch neural network on the right in only 1 line of code using nn_builder: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:UsageSee thiscolab notebookfor 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:FieldDescriptionDefaultinput_dimDimension of the input into the network. See below for more detail. Not needed for Tensorflow.N/Alayers_infoList to indicate the layers of the network you want. Exact requirements depend on network type, see below for more detailN/Aoutput_activationString to indicate the activation function you want the output to go through. Provide a list of strings if you want multiple output headsNo activationhidden_activationsString 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 activationsReLU after every hidden layerdropoutFloat to indicate what dropout probability you want applied after each hidden layer0initialiserString to indicate which initialiser you want used to initialise all the parametersPyTorch & TF Defaultbatch_normBoolean to indicate whether you want batch norm applied to the output of every hidden layerFalsecolumns of_data_to_be_embeddedList 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 networkNo embeddingsembedding_dimensionsIf 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 embeddingsy_rangeTuple of float or integers of the form (y_lower, y_upper) indicating the range you want to restrict the output values to in regression tasksNo rangerandom_seedInteger to indicate the random seed you want to use0return_final_seq_onlyOnly 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)TrueEach network type has slightly different requirements forinput_dimandlayers_infoas explained below:1. NNinput_dim: # Features in PyTorch, not needed for TensorFlowlayers_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. CNNinput_dim: (# Channels, Height, Width) in PyTorch, not needed for TensorFlowlayers_info: We expect the fieldlayers_infoto 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. RNNinput_dim: # Features in PyTorch, not needed for TensorFlowlayers_info: We expect the fieldlayers_infoto 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")ContributingTogether we can make something that is useful for thousands of people. Anyone is very welcome to contribute via a pull request. Please see theissuespage for ideas on the best areas to contribute to and try to:Add tests to the tests folder that cover any code you writeWrite comments for every functionCreate a colab notebook demonstrating how any extra functionality you created works