def hybrid_forward(self, F, inputs, states):   
batch_size = self._batch_size<EOL>beam_size = self._beam_size<EOL>vocab_size = self._vocab_size<EOL>state_info = self._state_info_func(batch_size)<EOL>step_input = _expand_to_beam_size(inputs, beam_size=beam_size,<EOL>batch_size=batch_size).astype(np.int32)<EOL>states = _expand_to_beam_size(states, beam_size=beam_size, batch_size=batch_size,<EOL>state_info=state_info)<EOL>state_structure, states = _extract_and_flatten_nested_structure(states)<EOL>if beam_size == <NUM_LIT:1>:<EOL><INDENT>init_scores = F.zeros(shape=(batch_size, <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>init_scores = F.concat(<EOL>F.zeros(shape=(batch_size, <NUM_LIT:1>)),<EOL>F.full(shape=(batch_size, beam_size - <NUM_LIT:1>), val=LARGE_NEGATIVE_FLOAT),<EOL>dim=<NUM_LIT:1>)<EOL><DEDENT>vocab_size = F.full(shape=(<NUM_LIT:1>,), val=vocab_size, dtype=np.int32)<EOL>batch_shift = F.arange(<NUM_LIT:0>, batch_size * beam_size, beam_size, dtype=np.int32)<EOL>def _loop_cond(_i, _samples, _indices, _step_input, _valid_length, _scores,beam_alive_mask, *_states):<EOL><INDENT>return F.sum(beam_alive_mask) > <NUM_LIT:0><EOL><DEDENT>def _loop_func(i, samples, indices, step_input, valid_length, scores,beam_alive_mask, *states):<EOL><INDENT>outputs, new_states = self._decoder(<EOL>step_input, _reconstruct_flattened_structure(state_structure, states))<EOL>step = i + <NUM_LIT:1><EOL>new_samples, new_valid_length, new_scores,chosen_word_ids, new_beam_alive_mask, new_new_states =self._updater(samples, valid_length, outputs, scores, step.astype(np.float32),<EOL>beam_alive_mask,<EOL>_extract_and_flatten_nested_structure(new_states)[-<NUM_LIT:1>],<EOL>vocab_size, batch_shift)<EOL>new_step_input = F.relu(chosen_word_ids).reshape((-<NUM_LIT:1>,))<EOL>new_indices = F.concat(<EOL>indices.slice_axis(axis=<NUM_LIT:0>, begin=<NUM_LIT:1>, end=None),<EOL>indices.slice_axis(axis=<NUM_LIT:0>, begin=<NUM_LIT:0>, end=<NUM_LIT:1>),<EOL>dim=<NUM_LIT:0>)<EOL>return [], (step, new_samples, new_indices, new_step_input, new_valid_length,new_scores, new_beam_alive_mask) + tuple(new_new_states)<EOL><DEDENT>_, pad_samples, indices, _, new_valid_length, new_scores, new_beam_alive_mask =F.contrib.while_loop(<EOL>cond=_loop_cond, func=_loop_func, max_iterations=self._max_length,<EOL>loop_vars=(<EOL>F.zeros(shape=(<NUM_LIT:1>,), dtype=np.int32),                        <EOL>F.zeros(shape=(batch_size, beam_size, self._max_length),<EOL>dtype=np.int32),                                    <EOL>F.arange(start=<NUM_LIT:0>, stop=self._max_length, dtype=np.int32),   <EOL>step_input,                                                 <EOL>F.ones(shape=(batch_size, beam_size), dtype=np.int32),      <EOL>init_scores,                                                <EOL>F.ones(shape=(batch_size, beam_size), dtype=np.int32),      <EOL>) + tuple(states)<EOL>)[<NUM_LIT:1>][:<NUM_LIT:7>]                                                            <EOL>samples = pad_samples.take(indices, axis=<NUM_LIT:2>)<EOL>def _then_func():<EOL><INDENT>new_samples = F.concat(<EOL>step_input.reshape((batch_size, beam_size, <NUM_LIT:1>)),<EOL>samples,<EOL>F.full(shape=(batch_size, beam_size, <NUM_LIT:1>), val=-<NUM_LIT:1>, dtype=np.int32),<EOL>dim=<NUM_LIT:2>,<EOL>name='<STR_LIT>')<EOL>new_new_valid_length = new_valid_length<EOL>return new_samples, new_new_valid_length<EOL><DEDENT>def _else_func():<EOL><INDENT>final_word = F.where(new_beam_alive_mask,<EOL>F.full(shape=(batch_size, beam_size), val=self._eos_id,<EOL>dtype=np.int32),<EOL>F.full(shape=(batch_size, beam_size), val=-<NUM_LIT:1>, dtype=np.int32))<EOL>new_samples = F.concat(<EOL>step_input.reshape((batch_size, beam_size, <NUM_LIT:1>)),<EOL>samples,<EOL>final_word.reshape((<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>)),<EOL>dim=<NUM_LIT:2>)<EOL>new_new_valid_length = new_valid_length + new_beam_alive_mask<EOL>return new_samples, new_new_valid_length<EOL><DEDENT>new_samples, new_new_valid_length =F.contrib.cond(F.sum(new_beam_alive_mask) == <NUM_LIT:0>, _then_func, _else_func)<EOL>return new_samples, new_scores, new_new_valid_length<EOL>
Sample by beam search.

        Parameters
        ----------
        F
        inputs : NDArray or Symbol
            The initial input of the decoder. Shape is (batch_size,).
        states : Object that contains NDArrays or Symbols
            The initial states of the decoder.
        Returns
        -------
        samples : NDArray or Symbol
            Samples draw by beam search. Shape (batch_size, beam_size, length). dtype is int32.
        scores : NDArray or Symbol
            Scores of the samples. Shape (batch_size, beam_size). We make sure that scores[i, :] are
            in descending order.
        valid_length : NDArray or Symbol
            The valid length of the samples. Shape (batch_size, beam_size). dtype will be int32.