CNN Decoder¶
- class textbox.module.Decoder.cnn_decoder.BasicCNNDecoder(input_size, latent_size, decoder_kernel_size, decoder_dilations, dropout_ratio)[source]¶
Bases:
Module
Basic Convolution Neural Network (CNN) decoder. Code Reference: https://github.com/kefirski/contiguous-succotash
- forward(decoder_input, noise)[source]¶
Implement the decoding process.
- Parameters
decoder_input (Torch.Tensor) – target sequence embedding, shape: [batch_size, sequence_length, embedding_size].
noise (Torch.Tensor) – latent code, shape: [batch_size, latent_size].
- Returns
output features, shape: [batch_size, sequence_length, feature_size].
- Return type
torch.Tensor
- training: bool¶
- class textbox.module.Decoder.cnn_decoder.HybridDecoder(embedding_size, latent_size, hidden_size, num_dec_layers, rnn_type, vocab_size)[source]¶
Bases:
Module
Hybrid Convolution Neural Network (CNN) and Recurrent Neural Network (RNN) decoder. Code Reference: https://github.com/kefirski/hybrid_rvae
- conv_decoder(latent_variable)[source]¶
Implement the CNN decoder.
- Parameters
latent_variable (Torch.Tensor) – latent code, shape: [batch_size, latent_size].
- Returns
output features, shape: [batch_size, sequence_length, feature_size].
- Return type
torch.Tensor
- forward(decoder_input, latent_variable)[source]¶
Implement the decoding process.
- Parameters
decoder_input (Torch.Tensor) – target sequence embedding, shape: [batch_size, sequence_length, embedding_size].
latent_variable (Torch.Tensor) – latent code, shape: [batch_size, latent_size].
- Returns
torch.Tensor: RNN output features, shape: [batch_size, sequence_length, feature_size].
torch.Tensor: CNN output features, shape: [batch_size, sequence_length, feature_size].
- Return type
tuple
- rnn_decoder(cnn_logits, decoder_input, initial_state=None)[source]¶
Implement the RNN decoder using CNN output.
- Parameters
cnn_logits (Torch.Tensor) – latent code, shape: [batch_size, sequence_length, feature_size].
decoder_input (Torch.Tensor) – target sequence embedding, shape: [batch_size, sequence_length, embedding_size].
initial_state (Torch.Tensor) – initial hidden states, default: None.
- Returns
Torch.Tensor: output features, shape: [batch_size, sequence_length, num_directions * hidden_size].
Torch.Tensor: hidden states, shape: [batch_size, num_layers * num_directions, hidden_size].
- Return type
tuple
- training: bool¶