(self, x, x_mask)
return output.contiguous()
Faster encoding that ignores any padding.
Faster encoding that ignores any padding.
Faster encoding that ignores any padding .
def _forward_unpadded(self, x, x_mask):
        """Faster encoding that ignores any padding."""
        # Transpose batch and sequence dims
        x = x.transpose(0, 1)

        # Encode all layers
        outputs = [x]
        for i in range(self.num_layers):
            rnn_input = outputs[-1]

            # Apply dropout to hidden input
#            if self.dropout_rate > 0:
#                rnn_input = F.dropout(rnn_input,
#                                      p=self.dropout_rate,
#                                      training=self.training)
            # Forward
            rnn_output = self.rnns[i](rnn_input)[0]
            outputs.append(rnn_output)

        # Concat hidden layers
        if self.concat_layers:
            output = torch.cat(outputs[1:], 2)
        else:
            output = outputs[-1]

        # Transpose back
        output = output.transpose(0, 1)

        # Dropout on output layer
        if self.dropout_output and self.dropout_rate > 0:
            output = F.dropout(output,
                               p=self.dropout_rate,
                               training=self.training)
        return output.contiguous()
def _forward_unpadded ( self , x , x_mask ) : # Transpose batch and sequence dims x = x . transpose ( 0 , 1 ) # Encode all layers outputs = [ x ] for i in range ( self . num_layers ) : rnn_input = outputs [ - 1 ] # Apply dropout to hidden input #            if self.dropout_rate > 0: #                rnn_input = F.dropout(rnn_input, #                                      p=self.dropout_rate, #                                      training=self.training) # Forward rnn_output = self . rnns [ i ] ( rnn_input ) [ 0 ] outputs . append ( rnn_output ) # Concat hidden layers if self . concat_layers : output = torch . cat ( outputs [ 1 : ] , 2 ) else : output = outputs [ - 1 ] # Transpose back output = output . transpose ( 0 , 1 ) # Dropout on output layer if self . dropout_output and self . dropout_rate > 0 : output = F . dropout ( output , p = self . dropout_rate , training = self . training ) return output . contiguous ( )