(self, minibatches, unlabeled=None)
| 914 | self.sd_reg = hparams["sd_reg"] |
| 915 | |
| 916 | def update(self, minibatches, unlabeled=None): |
| 917 | all_x = torch.cat([x for x, y in minibatches]) |
| 918 | all_y = torch.cat([y for x, y in minibatches]) |
| 919 | all_p = self.predict(all_x) |
| 920 | |
| 921 | loss = F.cross_entropy(all_p, all_y) |
| 922 | penalty = (all_p**2).mean() |
| 923 | objective = loss + self.sd_reg * penalty |
| 924 | |
| 925 | self.optimizer.zero_grad() |
| 926 | objective.backward() |
| 927 | self.optimizer.step() |
| 928 | |
| 929 | return {'loss': loss.item(), 'penalty': penalty.item()} |
| 930 | |
| 931 | |
| 932 | class ANDMask(ERM): |
no test coverage detected