(self, inputs)
| 10 | self.linear2 = nn.Linear(hidden_dim, num_class) |
| 11 | |
| 12 | def forward(self, inputs): |
| 13 | hidden = self.linear1(inputs) |
| 14 | activation = self.activate(hidden) |
| 15 | outputs = self.linear2(activation) |
| 16 | # 获得每个输入属于某一类别的概率(Softmax),然后再取对数 |
| 17 | # 取对数的目的是避免计算Softmax时可能产生的数值溢出问题 |
| 18 | log_probs = F.log_softmax(outputs, dim=1) |
| 19 | return log_probs |
| 20 | |
| 21 | # 异或问题的4个输入 |
| 22 | x_train = torch.tensor([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]) |
nothing calls this directly
no outgoing calls
no test coverage detected