class_docstr: A complete encoder-decoder model, with optional attention.
  
  A parent class which makes use of the contextual_embedding (such as a charlm)
  can make use of unsaved_modules when saving.
class_docstr_tok: ["A","complete","encoder-decoder","model",",","with","optional","attention",".","A","parent","class","which","makes","use","of","the","contextual_embedding","(","such","as","a","charlm",")","can","make","use","of","unsaved_modules","when","saving","."]
code: def init_weights(self):
      # initialize embeddings
      init_range = constant.EMB_INIT_RANGE
      if self.emb_matrix is not None:
          if isinstance(self.emb_matrix, np.ndarray):
              self.emb_matrix = torch.from_numpy(self.emb_matrix)
          assert self.emb_matrix.size() == (
              self.vocab_size,
              self.emb_dim,
          ), "Input embedding matrix must match size: {} x {}".format(
              self.vocab_size, self.emb_dim
          )
          self.embedding.weight.data.copy_(self.emb_matrix)
      else:
          self.embedding.weight.data.uniform_(-init_range, init_range)
      # decide finetuning
      if self.top <= 0:
          logger.debug("Do not finetune embedding layer.")
          self.embedding.weight.requires_grad = False
      elif self.top < self.vocab_size:
          logger.debug("Finetune top {} embeddings.".format(self.top))
          self.embedding.weight.register_hook(
              lambda x: utils.keep_partial_grad(x, self.top)
          )
      else:
          logger.debug("Finetune all embeddings.")
      # initialize pos embeddings
      if self.use_pos:
          self.pos_embedding.weight.data.uniform_(
              -init_range, init_range
          )
  
imports: import logging
  import torch
  from torch import nn
  import torch.nn.functional
  import numpy
  import stanza.models.common.seq2seq_constant
  from stanza.models.common import utils
  from stanza.models.common.seq2seq_modules import LSTMAttention
  from stanza.models.common.beam import Beam
label_desc: Use image node_id 3 for calling the Seq2SeqModel obj's underlying member method code with example usage: obj.init_weights() without return types