(self, minibatches, unlabeled=None)
| 98 | ) |
| 99 | |
| 100 | def update(self, minibatches, unlabeled=None): |
| 101 | all_x = torch.cat([x for x, y in minibatches]) |
| 102 | all_y = torch.cat([y for x, y in minibatches]) |
| 103 | loss = F.cross_entropy(self.predict(all_x), all_y) |
| 104 | |
| 105 | self.optimizer.zero_grad() |
| 106 | loss.backward() |
| 107 | self.optimizer.step() |
| 108 | |
| 109 | return {'loss': loss.item()} |
| 110 | |
| 111 | def predict(self, x): |
| 112 | return self.network(x) |