Skip to content

Commit

Permalink
Fix initialization of added embeddings (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
calpt authored Aug 12, 2022
1 parent dc311df commit ec2484f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/transformers/adapters/model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def add_embeddings(self, name, tokenizer, reference_embedding=None, reference_to
if embedding_dim is None:
embedding_dim = self.config.hidden_size
embedding = nn.Embedding(len(tokenizer), embedding_dim)
# Use same initialization as base Transformer model
embedding.weight.data.normal_(mean=0.0, std=0.02)
if embedding.padding_idx is not None:
embedding.weight.data[embedding.padding_idx].zero_()
embedding.requires_grad_(False)
if (reference_embedding is not None and reference_tokenizer is None) or (
reference_tokenizer is not None and reference_embedding is None
Expand Down

0 comments on commit ec2484f

Please sign in to comment.