Neural network 多输出层神经网络的监督学习训练

Neural network 多输出层神经网络的监督学习训练,neural-network,pytorch,supervised-learning,Neural Network,Pytorch,Supervised Learning,我有一个神经网络,它有多个输出层,根据我的代理所处的状态来确定softmax概率。以下是我的网络示例: class policy(nn.Module): def __init__(self): hidden_layer = 32 super(policy, self).__init__() self.affine1 = nn.Linear(3, hidden_layer) self.affine2 = nn.Linear(hidden_lay

我有一个神经网络,它有多个输出层,根据我的代理所处的状态来确定softmax概率。以下是我的网络示例:

class policy(nn.Module):
   def __init__(self):
      hidden_layer = 32
      super(policy, self).__init__()
      self.affine1 = nn.Linear(3, hidden_layer)
      self.affine2 = nn.Linear(hidden_layer, hidden_layer)
      self.output1 = nn.Linear(hidden_layer, 10)
      self.output2 = nn.Linear(hidden_layer, 5)
      self.output3 = nn.Linear(hidden_layer, 3)

   def forward(self, x):
      x = torch.nn.functional.relu(self.affine1(x))
      x = torch.nn.functional.relu(self.affine2(x))
      outputprobs1 = torch.nn.functional.softmax(self.output1(x), dim=-1)
      outputprobs2 = torch.nn.functional.softmax(self.output2(x), dim=-1)
      outputprobs3 = torch.nn.functional.softmax(self.output3(x), dim=-1)
      return outputprobs1, outputprobs2, outputprobs3
softmax概率表示我的代理将执行的某个操作,但该代理基于不同的状态有不同的操作。因为我知道我的代理应该执行哪些操作,所以我希望通过监督学习来培训策略。我计划使用torch.nn.CrossEntropyLoss(),因为这是一个多分类问题。此外,在每个事件中,模型多次从输出概率中进行选择

例如,假设我的代理可以处于3种状态:A、B和C。在状态A中,代理使用output1,在状态B中,代理使用output2,在状态C中,代理使用output3。因此,一个插曲中的一个例子可能是:

  • 代理在状态A下启动:选择操作9
  • 现在代理处于状态C:选择操作2
  • 现在代理处于状态B:选择操作4
  • 现在代理处于状态A:选择操作5
以下是我的问题:

我如何通过监督学习来培训这项政策?CrossEntropyLoss网站说我需要一个shape(N,C)输入。这里的C分别是10,5和3。我的想法是,我需要3个这样的输入,每个输出层一个。因此,我是否需要为每个输出层使用一个单独的损耗函数,或者我是否可以为所有输出层使用一个损耗函数传播其中一个输出层的损失是否会通过监督学习对其他层产生负面影响?

此外,我还想进一步说明如何获得CrossEntropyLoss输入所需的登录。为了获得这一点,我是否会使用
torch.logit(outputprobs1)?

非常感谢您的帮助,谢谢