简体   繁体   English

如何在DL4J中配置神经网络以产生多个二进制输出

[英]How to Configure Neural Network to Produce Multiple Binary Outputs in DL4J

I am learning DL4J , and I would like to configure a network that can accept a tuple of double values, and produce a tuple of binary values, in which multiple of them may be set to 1, and others set to 0. In the language of neural nets, would I cal this is multi-class one-hot encoding? 我正在学习DL4J ,我想配置一个网络,该网络可以接受一个双精度值元组,并生成一个二进制值元组,其中多个值可以设置为1,其他值可以设置为0。神经网络,请问这是多类一键编码吗?

Example: 例:

[3.5,  2.9, 15.0] -> [0, 0, 1, 0, 1]
[2.5, 12.5,  5.0] -> [1, 1, 0, 0, 1]
[5.9, 71.3,  0.7] -> [0, 1, 1, 0, 0]

etc. 等等

I have tried this: 我已经试过了:

MultiLayerConfiguration multiLayerConfiguration = 
    new NeuralNetConfiguration.Builder()
        .seed(System.nanoTime())
        .iterations(10000)
        .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
        .learningRate(0.1)
        .useDropConnect(false)
        .biasInit(0)
        .miniBatch(false)
        .updater(Updater.NESTEROVS)
        .list()
        .layer(0, new DenseLayer.Builder()
            .nIn(3)
            .nOut(8)
            .weightInit(WeightInit.XAVIER)
            .activation(Activation.SIGMOID)
            .build())
        .layer(1, new OutputLayer.Builder()
            .nIn(8)
            .nOut(5)
            .weightInit(WeightInit.XAVIER)
            .activation(Activation.SOFTMAX)
            .lossFunction(LossFunctions.LossFunction.RECONSTRUCTION_CROSSENTROPY)
            .build())
        .pretrain(false)
        .backprop(true)
        .build();

But I seem to be getting fractional values in the output as if the network is trying to evenly distribute the activation. 但是我似乎在输出中得到小数值,就好像网络试图均匀分配激活一样。 How do I configure the network to make it give me multiple 1's and 0's as a classification? 如何配置网络以使其具有多个1和0作为分类?

For example, if the output was 3 dimensional, I would want this: 例如,如果输出是3维的,则需要这样做:

[[0.00,  0.49,  0.51],  
 [0.50,  0.00,  0.50],  
 [0.50,  0.50,  0.00],  
 [0.33,  0.33,  0.34],  
 [0.00,  0.00,  1.00]]

To really be this: 要真正做到这一点:

[[0.00,  1.00,  1.00],  
 [1.00,  0.00,  1.00],  
 [1.00,  1.00,  0.00],  
 [1.00,  1.00,  1.00],  
 [0.00,  0.00,  1.00]]

You shouldn't use a softmax output for binary or multi class. 您不应将softmax输出用于二进制或多类。 You sigmoid and binary xent instead. 您可以选择Sigmoid和二进制Xent。

Also, this code looks a bit old. 另外,此代码看起来有些陈旧。 Make sure you are using 0.9.1. 确保您使用的是0.9.1。 Don't use reconstruction cross entropy -> use KL Divergence if you are doing unsupervised learning (autoencoders and the like) but for this case you shouldn't even be using recon error. 如果您要进行无监督学习(自动编码器等),请不要使用重构交叉熵->使用KL散度法,但在这种情况下,甚至不应该使用recon错误。

Also, the iterations knob is going away next release. 同样,下一个版本将取消迭代旋钮。 Use for loops instead. 改为使用循环。 That iterations knob is legacy (just leave it at 1 in the mean time) 该迭代旋钮是旧式的(在此同时将其保留为1)

Again, I strongly encourage you to follow our examples closer. 再次,我强烈建议您进一步遵循我们的示例。 We have everything you need in there for multi class classification or really any use case. 我们为您提供了多类分类或任何用例所需的一切。 If you can't find something try to do a keyword search in the repo. 如果找不到,请尝试在存储库中进行关键字搜索。 Failing that, ask on here our on our community gitter. 如果失败,请在这里询问我们的社区动向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM