を予測、私は一般的なニューラルネットワークアーキテクチャを持つようにしたいとしますニューラルネットワークは、2つのバイナリ変数
---> BinaryOutput_A
/
Input --> nnLayer -
\
---> BinaryOutput_B
入力は、2つのバイナリ変数(すなわち、A
を予測することになり、ニューラルネットワーク層を介して置かれています。
class NN(nn.Module):
def __init__(self, inputs):
super(NN, self).__init__()
# -- first layer
self.lin = nn.Linear(inputs,10)
# -- firstLayer --> binaryOutputA
self.l2a = nn.Linear(10,2)
# -- firstLayer --> binaryOutputB
self.l2b = nn.Linear(10,2)
def forward(self, inputs):
o = self.lin(inputs)
o1 = F.log_softmax(self.l2a(o))
o2 = F.log_softmax(self.l2b(o))
return o1, o2
:
[0 or 1]
と
B
が
[0 or 1]
であるpytorchで
、あなたがそのようなネットワークを作ることができます
私のtrain
の機能では、私はloss = loss_function(output, target)
で損失を計算します。その場合、l2a
とl2b
レイヤーの損失を適切にバックプレゼンテーションするには、loss.backward()
をconcat
target
l2a
とl2b
の適切なラベルで簡単に指定できますか?その意味では、出力は[outputPredictionA, outputPredictionB]
で、ターゲットを[labelA, labelB]
にすることができます.poltorchは各レイヤーに損失を適切に割り当てることを知っていますか?