在一行中建立神经网络

nn-builder的Python项目详细描述


DownloadsImagecontributions welcome

nn_builder

nn_builder允许您在不使用样板代码的情况下构建神经网络。您可以指定所需的网络类型并由它构建。

安装

pip install nn_builder

支持

Network TypeNNCNNRNN
PyTorch:heavy_check_mark::heavy_check_mark::heavy_check_mark:
TensorFlow 2.0:heavy_check_mark::heavy_check_mark::heavy_check_mark:

示例

左边是如何使用nn_builder在右边的一行代码中创建pytorch神经网络:

Screenshot

类似地,对于左侧的tensorflow,您可以使用nn_builder在右侧仅用一行代码创建cnn:

Screenshot

使用量

有关如何使用该模块的许多示例,请参见colab notebook。 目前支持三种类型的pytorch和tensorflow网络:nn、cnn和rnn。每个网络采用以下参数:

FieldDescriptionDefault
input_dimDimension of the input into the network. See below for more detail. Not needed for Tensorflow.N/A
layers_infoList to indicate the layers of the network you want. Exact requirements depend on network type, see below for more detailN/A
output_activationString to indicate the activation function you want the output to go through. Provide a list of strings if you want multiple output headsNo activation
hidden_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 layer
dropoutFloat to indicate what dropout probability you want applied after each hidden layer0
initialiserString to indicate which initialiser you want used to initialise all the parametersPyTorch & TF Default
batch_normBoolean to indicate whether you want batch norm applied to the output of every hidden layerFalse
columns 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 embeddings
embedding_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 embeddings
y_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 range
random_seedInteger to indicate the random seed you want to use0
return_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)True

每种网络类型对input-dimlayers-info的要求略有不同,如下所述:


1.nn
  • 输入维度:pytorch中的功能,tensorflow不需要
  • layers\u info:表示每个线性层所需隐藏单元数的整数列表。
  • 例如:
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:pytorch中的(channels,height,width),tensorflow不需要
  • layers\u info:我们希望字段layers\u info是一个列表列表,指示所需层的大小和类型。CNN中的每一层都可以是以下四种形式之一:
    • [“conv”,频道,内核大小,跨距,填充]
    • [“maxpool”,内核大小,跨距,填充]
    • [“avgpool”,内核大小,跨距,填充]
    • [“线性”,单位]
  • 对于pytorch网络内核大小,跨距、填充和单位必须是整数。对于tensorflow,它们都必须是整数,除了padding必须是{“valid”,“same”}中的一个
  • 例如:
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
  • 输入维度:pytorch中的功能,tensorflow不需要
  • layers\u info:我们希望字段layers\u info是一个列表列表,指示所需层的大小和类型。CNN中的每一层都可以是以下四种形式之一:
    • [“LSTM”,单位]
    • [“GRU”,单位]
    • [“线性”,单位]
  • 例如:
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")

贡献

我们可以一起创造出对成千上万人有用的东西。任何人都非常欢迎通过拉式请求贡献。请看issues 页面上有关于最佳贡献领域的想法,并尝试:

  1. 将测试添加到包含您编写的任何代码的“测试”文件夹中
  2. 为每个函数编写注释
  3. 创建一个colab笔记本,演示您创建的任何额外功能是如何工作的

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将getAttribute()scriptlet重写为JSP/HTML中的JSTL?   java接口,用于在KeyClope中执行电子邮件操作   java我试图将今天的日期添加到我的对象,但构造函数有问题   关于生成示例图表示(RDF或VEV元组)的java建议   httpclient在Java中使用空格编码URL的工作方式不正确   java NDimensional点类   java在编写查找ArrayList中最大整数索引的方法时遇到问题   java生成对象并放入arraylist,无重复项   在Java中使用泛型   在Java中使用“h=Math.min(h,h)”有什么逻辑原因吗?   安卓 Java for loop总是返回true   覆盖率java工具   java试图发送int时出现“空对象引用”错误