MCPcopy Create free account
hub / github.com/THUDM/GLM / forward

Method forward

model/modeling_bert.py:1001–1016  ·  view source on GitHub ↗
(self, input_ids, token_type_ids=None, attention_mask=None, masked_lm_labels=None,
                next_sentence_label=None, checkpoint_activations=False)

Source from the content-addressed store, hash-verified

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
1019class BertForMaskedLM(PreTrainedBertModel):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected