def __init__(
        self,
        encoded_size,
        vocab_size=None,
        embeddings=None,
        freeze=False,
        verbose=True,
        seed=123,
        **kwargs,
    ):
        """
        Args:
            encoded_size: (in) Output feature dimension of the Encoder, and
                input feature dimension of the LSTM
            vocab_size: The size of the vocabulary of the embeddings
                If embeddings=None, this helps to set the size of the randomly
                    initialized embeddings
                If embeddings != None, this is used to double check that the
                    provided embeddings have the intended size
            embeddings: An optional embedding Tensor
            freeze: If False, allow the embeddings to be updated
        """
        super().__init__(encoded_size)
        self.verbose = verbose

        # Load provided embeddings or randomly initialize new ones
        if embeddings is None:
            # Note: Need to set seed here for deterministic init
            if seed is not None:
                self._set_seed(seed)
            self.embeddings = nn.Embedding(vocab_size, encoded_size)
            if self.verbose:
                print(f"Using randomly initialized embeddings.")
        else:
            self.embeddings = self._load_pretrained(embeddings)
            if self.verbose:
                print(f"Using pretrained embeddings.")

        # Freeze or not
        self.embeddings.weight.requires_grad = not freeze

        if self.verbose:
            print(
                f"Embeddings shape = ({self.embeddings.num_embeddings}, "
                f"{self.embeddings.embedding_dim})"
            )
            print(f"The embeddings are {'' if freeze else 'NOT '}FROZEN")
def __init__ ( self , encoded_size , vocab_size = None , embeddings = None , freeze = False , verbose = True , seed = 123 , ** kwargs , ) : super ( ) . __init__ ( encoded_size ) self . verbose = verbose if embeddings is None : if seed is not None : self . _set_seed ( seed ) self . embeddings = nn . Embedding ( vocab_size , encoded_size ) if self . verbose : print ( f"Using randomly initialized embeddings." ) else : self . embeddings = self . _load_pretrained ( embeddings ) if self . verbose : print ( f"Using pretrained embeddings." ) self . embeddings . weight . requires_grad = not freeze if self . verbose : print ( f"Embeddings shape = ({self.embeddings.num_embeddings}, " f"{self.embeddings.embedding_dim})" ) print ( f"The embeddings are {'' if freeze else 'NOT '}FROZEN" )
Args:
            encoded_size: (in) Output feature dimension of the Encoder, and
                input feature dimension of the LSTM
            vocab_size: The size of the vocabulary of the embeddings
                If embeddings=None, this helps to set the size of the randomly
                    initialized embeddings
                If embeddings != None, this is used to double check that the
                    provided embeddings have the intended size
            embeddings: An optional embedding Tensor
            freeze: If False, allow the embeddings to be updated