Ejemplo n.º 1
0
 def __init__(self,
              word_embeddings_size,
              hidden_size,
              embeddings_freeze=False):
     super(LanguageEncodingLSTM, self).__init__()
     self.lstm_cell = LSTMCell(word_embeddings_size, hidden_size, bias=True)
     self.freeze(embeddings_freeze)
Ejemplo n.º 2
0
 def __init__(self, joint_embed_size, language_encoding_lstm_size,
              hidden_size):
     super(LanguageGenerationLSTM, self).__init__()
     self.lstm_cell = LSTMCell(language_encoding_lstm_size +
                               joint_embed_size,
                               hidden_size,
                               bias=True)
Ejemplo n.º 3
0
    def __init__(self,
                 word_map,
                 embed_dim=512,
                 encoder_output_dim=2048,
                 pretrained_embeddings=None,
                 embeddings_freeze=False,
                 hidden_size=512,
                 attention_dim=512,
                 dropout=0.1):
        super(SATDecoder,
              self).__init__(word_map, embed_dim, encoder_output_dim,
                             pretrained_embeddings, embeddings_freeze)

        self.hidden_size = hidden_size
        self.attention_dim = attention_dim
        self.dropout_ratio = dropout

        # LSTM layers
        self.decode_step = LSTMCell(
            input_size=encoder_output_dim +
            self.embed_dim,  # if layer == 0 else hidden_size,
            hidden_size=hidden_size,
            bias=True)
        #self.layers = nn.ModuleList([
        #    LSTMCell(input_size=encoder_output_dim + embed_dim if layer == 0 else hidden_size,
        #             hidden_size=hidden_size, bias=True)
        #    for layer in range(num_layers)
        #])

        # Attention Layer
        self.attention = AttentionLayer(encoder_output_dim, hidden_size,
                                        attention_dim)

        # Linear layers to find initial states of LSTMs
        self.init_h = nn.Linear(encoder_output_dim, hidden_size)
        self.init_c = nn.Linear(encoder_output_dim, hidden_size)

        # Gating scalars and sigmoid layer (cf. section 4.2.1 of the paper)
        self.f_beta = nn.Linear(hidden_size, encoder_output_dim)
        self.sigmoid = nn.Sigmoid()

        # Dropout layer
        self.dropout = nn.Dropout(p=dropout)

        # Linear layers for output generation
        self.linear_o = nn.Linear(embed_dim, self.vocab_size)
        self.linear_h = nn.Linear(hidden_size, self.embed_dim)
        self.linear_z = nn.Linear(encoder_output_dim, self.embed_dim)
Ejemplo n.º 4
0
 def __init__(self, attn_lstm_dim, viz_attn_dim, hidden_size):
     super(LanguageLSTM, self).__init__()
     self.lstm_cell = LSTMCell(input_size=attn_lstm_dim + viz_attn_dim,
                               hidden_size=hidden_size,
                               bias=True)
Ejemplo n.º 5
0
 def __init__(self, embed_dim, lang_lstm_dim, encoder_dim, hidden_size):
     super(AttentionLSTM, self).__init__()
     self.lstm_cell = LSTMCell(input_size=lang_lstm_dim + encoder_dim +
                               embed_dim,
                               hidden_size=hidden_size,
                               bias=True)