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

Method forward

model/modeling_bert.py:1266–1282  ·  view source on GitHub ↗
(self, input_ids, token_type_ids=None, attention_mask=None, labels=None, checkpoint_activations=False)

Source from the content-addressed store, hash-verified

1264 self.apply(self.init_bert_weights)
1265
1266 def forward(self, input_ids, token_type_ids=None, attention_mask=None, labels=None, checkpoint_activations=False):
1267 batch_size, num_choices = input_ids.shape[:2]
1268 flat_input_ids = input_ids.reshape(-1, input_ids.size(-1))
1269 flat_token_type_ids = token_type_ids.reshape(-1, token_type_ids.size(-1))
1270 flat_attention_mask = attention_mask.reshape(-1, attention_mask.size(-1))
1271 _, pooled_output = self.bert(flat_input_ids, flat_token_type_ids, flat_attention_mask,
1272 output_all_encoded_layers=False, checkpoint_activations=checkpoint_activations)
1273 pooled_output = self.dropout(pooled_output)
1274 logits = self.classifier(pooled_output)
1275 reshaped_logits = logits.reshape(-1, num_choices)
1276
1277 if labels is not None:
1278 loss_fct = CrossEntropyLoss()
1279 loss = loss_fct(reshaped_logits, labels)
1280 return loss
1281 else:
1282 return reshaped_logits
1283
1284
1285class BertForTokenClassification(PreTrainedBertModel):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected