在一行中建立神经网络

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如何强制用户在允许访问活动之前处理对话框?我的许可证代码怎么了?   java ArraysList作为JSON   mysql如何在java中创建包含多个可选where子句的搜索语句?   java如何让Apache Camel在“直接”路径的末尾删除文件?   使用socket在两个Androids之间进行java实时数据传输。IO(websocket)和4G   如何在java中实现两个CORBA服务器之间的通信   会话树xml表示为java对象   java Skype4Java编号swtwin323325   java RecyclerView getAdapterPosition()不工作:第一次单击返回正确位置,第二次单击返回1   java在$TOMCAT/conf/context上为JNDI设置资源。xml   java为什么第二个矩形冲突在第一个矩形冲突时不起作用?   JScrollPane上的java JTextArea未出现在JPanel上   java如何将实现的PriorityQueue打印为字符串?   jpa使用Jersey更新用户角色RESTJava(JAXRS)