class_docstr: Generate sentence representation using the open source HuggingFace Electra
  model. This class implements loading the model weights from a
  pre-trained model file.
class_docstr_tok: ["Generate","sentence","representation","using","the","open","source","HuggingFace","Electra","model",".","This","class","implements","loading","the","model","weights","from","a","pre-trained","model","file","."]
code: def __init__(
      self, config: Config, output_encoded_layers: bool, *args, **kwargs
  ) -> None:
      super().__init__(
          config, output_encoded_layers=output_encoded_layers
      )
      # Load config
      config_file = os.path.join(config.electra_cpt_dir, "config.json")
      electra_config = ElectraConfig.from_json_file(config_file)
      print("Electra model config {}".format(electra_config))
      # Instantiate model.
      model = ElectraModel(electra_config)
      weights_path = os.path.join(
          config.electra_cpt_dir, "pytorch_model.bin"
      )
      # load pre-trained weights if weights_path exists
      if config.load_weights and PathManager.isfile(weights_path):
          state_dict = torch.load(weights_path)
  
          missing_keys: List[str] = []
          unexpected_keys: List[str] = []
          error_msgs: List[str] = []
          # copy state_dict so _load_from_state_dict can modify it
          metadata = getattr(state_dict, "_metadata", None)
          state_dict = state_dict.copy()
  
          if metadata is not None:
              state_dict._metadata = metadata
  
          def load(module, prefix=""):
              local_metadata = (
                  {}
                  if metadata is None
                  else metadata.get(prefix[:-1], {})
              )
              module._load_from_state_dict(
                  state_dict,
                  prefix,
                  local_metadata,
                  True,
                  missing_keys,
                  unexpected_keys,
                  error_msgs,
              )
              for name, child in module._modules.items():
                  if child is not None:
                      load(child, prefix + name + ".")
  
          load(
              model,
              prefix="" if hasattr(model, "electra") else "electra.",
          )
          if len(missing_keys) > 0:
              print(
                  "Weights of {} not initialized from pretrained model: {}".format(
                      model.__class__.__name__, missing_keys
                  )
              )
          if len(unexpected_keys) > 0:
              print(
                  "Weights from pretrained model not used in {}: {}".format(
                      model.__class__.__name__, unexpected_keys
                  )
              )
  
      self.electra = model
      log_class_usage(__class__)
  
file_path: pytext/pytext/models/representations/huggingface_electra_sentence_encoder.py
imports: import os
  from typing import List, Tuple
  import torch
  from pytext.config import ConfigBase
  from pytext.models.representations.transformer_sentence_encoder_base import TransformerSentenceEncoderBase
  from pytext.utils.file_io import PathManager
  from pytext.utils.usage import log_class_usage
  from transformers.modeling_electra import ElectraConfig, ElectraModel
label_desc: Use image node_id 1 to create a new HuggingFaceElectraSentenceEncoder object from inherited base classes: TransformerSentenceEncoderBase with example: obj = HuggingFaceElectraSentenceEncoder(config, output_encoded_layers)