fix masked_lm for loading in pytext
Summary: lm_output_learned_bias doesn't exist when loading the model for fine-tuning
@@ -174,6 +174,7 @@ class MaskedLMEncoder(FairseqEncoder):
self.activation_fn = utils.get_activation_fn(args.activation_fn)
self.layer_norm = LayerNorm(args.encoder_embed_dim)
+ self.lm_output_learned_bias = None
if self.load_softmax:
self.lm_output_learned_bias = nn.Parameter(torch.zeros(self.vocab_size))
@@ -229,6 +230,7 @@ class MaskedLMEncoder(FairseqEncoder):
elif self.embed_out is not None:
x = self.embed_out(x)
+ if self.lm_output_learned_bias is not None:
x = x + self.lm_output_learned_bias
sentence_logits = None
if self.sentence_projection_layer:
