(self, input_ids, token_type_ids=None, attention_mask=None, masked_lm_labels=None,
next_sentence_label=None, checkpoint_activations=False)
| 999 | self.apply(self.init_bert_weights) |
| 1000 | |
| 1001 | def forward(self, input_ids, token_type_ids=None, attention_mask=None, masked_lm_labels=None, |
| 1002 | next_sentence_label=None, checkpoint_activations=False): |
| 1003 | sequence_output, pooled_output = self.bert(input_ids, token_type_ids, attention_mask, |
| 1004 | output_all_encoded_layers=False, |
| 1005 | checkpoint_activations=checkpoint_activations) |
| 1006 | prediction_scores, seq_relationship_score = self.cls(sequence_output, pooled_output) |
| 1007 | |
| 1008 | if masked_lm_labels is not None and next_sentence_label is not None: |
| 1009 | loss_fct = CrossEntropyLoss(ignore_index=-1) |
| 1010 | masked_lm_loss = loss_fct(prediction_scores.view(-1, self.config.vocab_size).float(), |
| 1011 | masked_lm_labels.view(-1)) |
| 1012 | next_sentence_loss = loss_fct(seq_relationship_score.view(-1, 2).float(), next_sentence_label.view(-1)) |
| 1013 | total_loss = masked_lm_loss + next_sentence_loss |
| 1014 | return total_loss |
| 1015 | else: |
| 1016 | return prediction_scores, seq_relationship_score |
| 1017 | |
| 1018 | |
| 1019 | class BertForMaskedLM(PreTrainedBertModel): |
nothing calls this directly
no outgoing calls
no test coverage detected