This class can be used to compose several encoders in sequence.
Among other things, this can be used to add a "pre-contextualizer" before a Seq2SeqEncoder.
- encoders :
List[Seq2SeqEncoder], required. A non-empty list of encoders to compose. The encoders must match in bidirectionality.
ComposeEncoder.forward(self, inputs:torch.Tensor, mask:torch.LongTensor=None) -> torch.Tensor
- inputs :
torch.Tensor, required. A tensor of shape (batch_size, timesteps, input_dim)
- mask :
torch.LongTensor, optional (default = None). A tensor of shape (batch_size, timesteps).
A tensor computed by composing the sequence of encoders.
ComposeEncoder.get_input_dim(self) -> int
Returns the dimension of the vector input for each element in the sequence input
Seq2SeqEncoder. This is
not the shape of the input tensor, but the
last element of that shape.
ComposeEncoder.get_output_dim(self) -> int
Returns the dimension of each vector in the sequence output by this
not the shape of the returned tensor, but the last element of that shape.
ComposeEncoder.is_bidirectional(self) -> bool
True if this encoder is bidirectional. If so, we assume the forward direction
of the encoder is the first half of the final dimension, and the backward direction is the