Initialize the weights
(self, module)
| 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 | |
| 564 | BERT_START_DOCSTRING = r""" |
no outgoing calls
no test coverage detected