def hybrid_forward(self, F, samples, valid_length, outputs, scores, step, beam_alive_mask,   <EOL>states, vocab_size, batch_shift):
beam_size = self._beam_size<EOL>beam_alive_mask_bcast = F.expand_dims(beam_alive_mask, axis=<NUM_LIT:2>).astype(np.float32)<EOL>candidate_scores = self._scorer(outputs.reshape(shape=(-<NUM_LIT:4>, -<NUM_LIT:1>, beam_size, <NUM_LIT:0>)),<EOL>scores, step)<EOL>candidate_scores = F.broadcast_mul(beam_alive_mask_bcast, candidate_scores) +F.broadcast_mul(<NUM_LIT:1> - beam_alive_mask_bcast,<EOL>F.ones_like(candidate_scores) * LARGE_NEGATIVE_FLOAT)<EOL>finished_scores = F.where(beam_alive_mask,<EOL>F.ones_like(scores) * LARGE_NEGATIVE_FLOAT, scores)<EOL>candidate_scores = F.concat(candidate_scores.reshape(shape=(<NUM_LIT:0>, -<NUM_LIT:1>)),<EOL>finished_scores, dim=<NUM_LIT:1>)<EOL>new_scores, indices = F.topk(candidate_scores, axis=<NUM_LIT:1>, k=beam_size, ret_typ='<STR_LIT>')<EOL>indices = indices.astype(np.int32)<EOL>use_prev = F.broadcast_greater_equal(indices, beam_size * vocab_size)<EOL>chosen_word_ids = F.broadcast_mod(indices, vocab_size)<EOL>beam_ids = F.where(use_prev,<EOL>F.broadcast_minus(indices, beam_size * vocab_size),<EOL>F.floor(F.broadcast_div(indices, vocab_size)))<EOL>batch_beam_indices = F.broadcast_add(beam_ids, F.expand_dims(batch_shift, axis=<NUM_LIT:1>))<EOL>chosen_word_ids = F.where(use_prev,<EOL>-F.ones_like(indices),<EOL>chosen_word_ids)<EOL>selected_samples = F.take(samples.reshape(shape=(-<NUM_LIT:3>, <NUM_LIT:0>)),<EOL>batch_beam_indices.reshape(shape=(-<NUM_LIT:1>,)))<EOL>new_samples = F.concat(selected_samples,<EOL>chosen_word_ids.reshape(shape=(-<NUM_LIT:1>, <NUM_LIT:1>)), dim=<NUM_LIT:1>).reshape(shape=(-<NUM_LIT:4>, -<NUM_LIT:1>, beam_size, <NUM_LIT:0>))<EOL>if self._single_step:<EOL><INDENT>new_samples = new_samples.slice_axis(axis=<NUM_LIT:2>, begin=<NUM_LIT:1>, end=None)<EOL><DEDENT>new_valid_length = F.take(valid_length.reshape(shape=(-<NUM_LIT:1>,)),<EOL>batch_beam_indices.reshape(shape=(-<NUM_LIT:1>,))).reshape((-<NUM_LIT:1>, beam_size))+ <NUM_LIT:1> - use_prev<EOL>new_states = _choose_states(F, states, self._state_info, batch_beam_indices.reshape((-<NUM_LIT:1>,)))<EOL>beam_alive_mask = F.take(beam_alive_mask.reshape(shape=(-<NUM_LIT:1>,)),<EOL>batch_beam_indices.reshape(shape=(-<NUM_LIT:1>,))).reshape(shape=(-<NUM_LIT:1>, beam_size)) * (chosen_word_ids != self._eos_id)<EOL>return new_samples, new_valid_length, new_scores,chosen_word_ids, beam_alive_mask, new_states<EOL>
Parameters
----------
F
samples : NDArray or Symbol
    The current samples generated by beam search.
    When single_step is True, (batch_size, beam_size, max_length).
    When single_step is False, (batch_size, beam_size, L).
valid_length : NDArray or Symbol
    The current valid lengths of the samples
outputs : NDArray or Symbol
    Outputs from predictor. If from_logits was set to True in scorer, then it's the
    log probability of the current step. Else, it's the unnormalized outputs before
    softmax or log_softmax. Shape (batch_size * beam_size, V).
scores : NDArray or Symbol
    The previous scores. Shape (batch_size, beam_size)
step : NDArray or Symbol
    The current step for doing beam search. Begins from 1. Shape (1,)
beam_alive_mask : NDArray or Symbol
    Shape (batch_size, beam_size)
states : nested structure of NDArrays/Symbols
    Each NDArray/Symbol should have shape (N, ...) when state_info is None,
    or same as the layout in state_info when it's not None.
vocab_size : NDArray or Symbol
    Shape (1,)
batch_shift : NDArray or Symbol
    Contains [0, beam_size, 2 * beam_size, ..., (batch_size - 1) * beam_size].
    Shape (batch_size,)

Returns
-------
new_samples : NDArray or Symbol or an empty list
    The updated samples.
    When single_step is True, it is an empty list.
    When single_step is False, shape (batch_size, beam_size, L + 1)
new_valid_length : NDArray or Symbol
    Valid lengths of the samples. Shape (batch_size, beam_size)
new_scores : NDArray or Symbol
    Shape (batch_size, beam_size)
chosen_word_ids : NDArray or Symbol
    The chosen word ids of the step. Shape (batch_size, beam_size). If it's negative,
    no word will be appended to the beam.
beam_alive_mask : NDArray or Symbol
    Shape (batch_size, beam_size)
new_states : nested structure of NDArrays/Symbols
    Inner NDArrays have shape (batch_size * beam_size, ...)