(cls)
| 323 | |
| 324 | @classmethod |
| 325 | def default_config(cls): |
| 326 | cfg: BertModel.Config = super().default_config() |
| 327 | # param_init matches original tf implementation. The Hugging Face implementation uses plain |
| 328 | # GaussianInitializer which empirically does not work as well (gradients quickly vanish). |
| 329 | # https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/modeling.py#L377 |
| 330 | # https://github.com/huggingface/transformers/blob/aa6cfe9c4b073b2c058a78fc2d26fe3fbe0ad70b/src/transformers/models/bert/modeling_bert.py#L726 |
| 331 | cfg.param_init = DefaultInitializer.default_config().set( |
| 332 | init_by_param_name={ |
| 333 | PARAM_REGEXP_WEIGHT: WeightInitializer.default_config().set( |
| 334 | fan=None, |
| 335 | distribution="truncated_normal", |
| 336 | scale=0.02, |
| 337 | ) |
| 338 | } |
| 339 | ) |
| 340 | # By default, assume `head` employs tied weights. |
| 341 | cfg.head = BertLMHead.default_config().set( |
| 342 | inner_head=RedirectToSharedModule.default_config().set( |
| 343 | shared_module="shared_token_emb", |
| 344 | # Map the method name here so the child can just call forward directly. |
| 345 | method_map=dict(forward="attend"), |
| 346 | ) |
| 347 | ) |
| 348 | return cfg |
| 349 | |
| 350 | |
| 351 | def bert_embedding_config( |
no test coverage detected