(self, input_ids, token_type_ids=None, attention_mask=None, start_positions=None, end_positions=None,
checkpoint_activations=False)
| 1424 | self.apply(self.init_bert_weights) |
| 1425 | |
| 1426 | def forward(self, input_ids, token_type_ids=None, attention_mask=None, start_positions=None, end_positions=None, |
| 1427 | checkpoint_activations=False): |
| 1428 | sequence_output, _ = self.bert(input_ids, token_type_ids, attention_mask, output_all_encoded_layers=False, |
| 1429 | checkpoint_activations=checkpoint_activations) |
| 1430 | logits = self.qa_outputs(sequence_output) |
| 1431 | start_logits, end_logits = logits.split(1, dim=-1) |
| 1432 | start_logits = start_logits.squeeze(-1) |
| 1433 | end_logits = end_logits.squeeze(-1) |
| 1434 | |
| 1435 | if start_positions is not None and end_positions is not None: |
| 1436 | # If we are on multi-GPU, split add a dimension |
| 1437 | if len(start_positions.size()) > 1: |
| 1438 | start_positions = start_positions.squeeze(-1) |
| 1439 | if len(end_positions.size()) > 1: |
| 1440 | end_positions = end_positions.squeeze(-1) |
| 1441 | # sometimes the start/end positions are outside our model inputs, we ignore these terms |
| 1442 | ignored_index = start_logits.size(1) |
| 1443 | start_positions.clamp_(0, ignored_index) |
| 1444 | end_positions.clamp_(0, ignored_index) |
| 1445 | |
| 1446 | loss_fct = CrossEntropyLoss(ignore_index=ignored_index) |
| 1447 | start_loss = loss_fct(start_logits, start_positions) |
| 1448 | end_loss = loss_fct(end_logits, end_positions) |
| 1449 | total_loss = (start_loss + end_loss) / 2 |
| 1450 | return total_loss |
| 1451 | else: |
| 1452 | return start_logits, end_logits |
nothing calls this directly
no outgoing calls
no test coverage detected