MCPcopy Create free account
hub / github.com/SooLab/CGFormer / BertPreTrainedModel

Class BertPreTrainedModel

bert/modeling_bert.py:542–561  ·  view source on GitHub ↗

An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.

Source from the content-addressed store, hash-verified

540
541
542class BertPreTrainedModel(PreTrainedModel):
543 """ An abstract class to handle weights initialization and
544 a simple interface for downloading and loading pretrained models.
545 """
546
547 config_class = BertConfig
548 load_tf_weights = load_tf_weights_in_bert
549 base_model_prefix = "bert"
550
551 def _init_weights(self, module):
552 """ Initialize the weights """
553 if isinstance(module, (nn.Linear, nn.Embedding)):
554 # Slightly different from the TF version which uses truncated_normal for initialization
555 # cf https://github.com/pytorch/pytorch/pull/5617
556 module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
557 elif isinstance(module, BertLayerNorm):
558 module.bias.data.zero_()
559 module.weight.data.fill_(1.0)
560 if isinstance(module, nn.Linear) and module.bias is not None:
561 module.bias.data.zero_()
562
563
564BERT_START_DOCSTRING = r"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected