(self, batch, batch_idx)
| 55 | return {'loss': loss} |
| 56 | |
| 57 | def validation_step(self, batch, batch_idx): |
| 58 | pos_ids, pos_mask, neg_ids, neg_mask = batch |
| 59 | |
| 60 | neg_ids = neg_ids.view(-1, neg_ids.shape[-1]) |
| 61 | neg_mask = neg_mask.view(-1, neg_mask.shape[-1]) |
| 62 | |
| 63 | pos_outputs = self(pos_ids, attention_mask=pos_mask, labels=torch.ones(pos_ids.shape[0], dtype=torch.uint8).to(pos_ids.get_device())) |
| 64 | neg_outputs = self(neg_ids, attention_mask=neg_mask, labels=torch.zeros(neg_ids.shape[0], dtype=torch.uint8).to(neg_ids.get_device())) |
| 65 | |
| 66 | loss_scale = 1.0 |
| 67 | loss = pos_outputs.loss + loss_scale * neg_outputs.loss |
| 68 | |
| 69 | pos_logits = pos_outputs.logits |
| 70 | pos_preds = torch.argmax(pos_logits, axis=1) |
| 71 | self.val_acc(pos_preds.cpu(), torch.ones(pos_ids.shape[0], dtype=torch.uint8).cpu()) |
| 72 | |
| 73 | neg_logits = neg_outputs.logits |
| 74 | neg_preds = torch.argmax(neg_logits, axis=1) |
| 75 | self.val_acc(neg_preds.cpu(), torch.zeros(neg_ids.shape[0], dtype=torch.uint8).cpu()) |
| 76 | |
| 77 | self.log('val_acc', self.val_acc) |
| 78 | |
| 79 | return {'loss': loss} |
| 80 | |
| 81 | def test_step(self, batch, batch_idx): |
| 82 | pos_ids, pos_mask, neg_ids, neg_mask = batch |
nothing calls this directly
no outgoing calls
no test coverage detected