def hybrid_forward(self, F, inputs, states=None, valid_length=None, position_weight=None):
        # pylint: disable=arguments-differ
        """

        Parameters
        ----------
        inputs : NDArray or Symbol, Shape(batch_size, length, C_in)
        states : list of NDArray or Symbol
        valid_length : NDArray or Symbol
        position_weight : NDArray or Symbol

        Returns
        -------
        outputs : NDArray or Symbol, or List[NDArray] or List[Symbol]
            If output_all_encodings flag is False, then the output of the last encoder.
            If output_all_encodings flag is True, then the list of all outputs of all encoders.
            In both cases, shape of the tensor(s) is/are (batch_size, length, C_out)
        additional_outputs : list
            Either be an empty list or contains the attention weights in this step.
            The attention weights will have shape (batch_size, length, length) or
            (batch_size, num_heads, length, length)

        """
        if states is not None:
            steps = states[-1]
            # Positional Encoding
            positional_embed = F.Embedding(steps, position_weight, self._max_length, self._units)
            inputs = F.broadcast_add(inputs, F.expand_dims(positional_embed, axis=0))
        if self._dropout:
            if self._use_layer_norm_before_dropout:
                inputs = self.layer_norm(inputs)
                inputs = self.dropout_layer(inputs)
            else:
                inputs = self.dropout_layer(inputs)
                inputs = self.layer_norm(inputs)
        else:
            inputs = self.layer_norm(inputs)
        outputs = inputs
        if valid_length is not None:
            mask = states[-2]
        else:
            mask = None

        all_encodings_outputs = []
        additional_outputs = []
        for cell in self.transformer_cells:
            outputs, attention_weights = cell(inputs, mask)
            inputs = outputs
            if self._output_all_encodings:
                if valid_length is not None:
                    outputs = F.SequenceMask(outputs, sequence_length=valid_length,
                                             use_sequence_length=True, axis=1)
                all_encodings_outputs.append(outputs)

            if self._output_attention:
                additional_outputs.append(attention_weights)

        if valid_length is not None:
            outputs = F.SequenceMask(outputs, sequence_length=valid_length,
                                     use_sequence_length=True, axis=1)

        if self._output_all_encodings:
            return all_encodings_outputs, additional_outputs
        else:
            return outputs, additional_outputs
def hybrid_forward ( self , F , inputs , states = None , valid_length = None , position_weight = None ) : if states is not None : steps = states [ - 1 ] positional_embed = F . Embedding ( steps , position_weight , self . _max_length , self . _units ) inputs = F . broadcast_add ( inputs , F . expand_dims ( positional_embed , axis = 0 ) ) if self . _dropout : if self . _use_layer_norm_before_dropout : inputs = self . layer_norm ( inputs ) inputs = self . dropout_layer ( inputs ) else : inputs = self . dropout_layer ( inputs ) inputs = self . layer_norm ( inputs ) else : inputs = self . layer_norm ( inputs ) outputs = inputs if valid_length is not None : mask = states [ - 2 ] else : mask = None all_encodings_outputs = [ ] additional_outputs = [ ] for cell in self . transformer_cells : outputs , attention_weights = cell ( inputs , mask ) inputs = outputs if self . _output_all_encodings : if valid_length is not None : outputs = F . SequenceMask ( outputs , sequence_length = valid_length , use_sequence_length = True , axis = 1 ) all_encodings_outputs . append ( outputs ) if self . _output_attention : additional_outputs . append ( attention_weights ) if valid_length is not None : outputs = F . SequenceMask ( outputs , sequence_length = valid_length , use_sequence_length = True , axis = 1 ) if self . _output_all_encodings : return all_encodings_outputs , additional_outputs else : return outputs , additional_outputs
Parameters
        ----------
        inputs : NDArray or Symbol, Shape(batch_size, length, C_in)
        states : list of NDArray or Symbol
        valid_length : NDArray or Symbol
        position_weight : NDArray or Symbol

        Returns
        -------
        outputs : NDArray or Symbol, or List[NDArray] or List[Symbol]
            If output_all_encodings flag is False, then the output of the last encoder.
            If output_all_encodings flag is True, then the list of all outputs of all encoders.
            In both cases, shape of the tensor(s) is/are (batch_size, length, C_out)
        additional_outputs : list
            Either be an empty list or contains the attention weights in this step.
            The attention weights will have shape (batch_size, length, length) or
            (batch_size, num_heads, length, length)