class_docstr: Masked language model for BERT style pre-training.
class_docstr_tok: ["Masked","language","model","for","BERT","style","pre-training","."]
code: def from_config(
      cls, config: Config, tensorizers: Dict[str, Tensorizer]
  ):
      token_tensorizer = tensorizers["tokens"]
      vocab = token_tensorizer.vocab
  
      encoder = create_module(
          config.encoder,
          output_encoded_layers=True,
          padding_idx=vocab.get_pad_index(),
          vocab_size=vocab.__len__(),
      )
      decoder = create_module(
          config.decoder,
          in_dim=encoder.representation_dim,
          out_dim=len(vocab),
      )
      if getattr(config.encoder, "apply_bert_init", False):
          decoder.apply(init_bert_params)
      # if weights are not shared then we need to ensure that the decoder
      # params are initialized in the same was as the encoder params
      if config.tie_weights:
          list(decoder.mlp.modules())[
              -1
          ].weight = encoder._embedding().weight
  
      output_layer = create_module(config.output_layer, labels=vocab)
      return cls(
          encoder,
          decoder,
          output_layer,
          token_tensorizer,
          vocab,
          mask_prob=config.mask_prob,
          mask_bos=config.mask_bos,
          masking_strategy=config.masking_strategy,
      )
  
imports: from typing import Dict, List
  import torch
  from fairseq.modules.transformer_sentence_encoder import init_bert_params
  from pytext.common.constants import SpecialTokens, Stage
  from pytext.config import ConfigBase
  from pytext.data.bert_tensorizer import BERTTensorizerBase
  from pytext.data.tensorizers import Tensorizer
  from pytext.data.utils import Vocabulary
  from pytext.models.decoders.mlp_decoder import MLPDecoder
  from pytext.models.masking_utils import frequency_based_masking, MaskingStrategy, random_masking
  from pytext.models.model import BaseModel
  from pytext.models.module import create_module
  from pytext.models.output_layers.lm_output_layer import LMOutputLayer
  from pytext.models.representations.transformer_sentence_encoder import TransformerSentenceEncoder
  from pytext.models.representations.transformer_sentence_encoder_base import TransformerSentenceEncoderBase
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 1 for calling the MaskedLanguageModel obj's underlying member method code with example usage: obj.from_config(cls, config, tensorizers) and returns: cls