(self, topi, topv, decoder_state, att_map=None,
                lm_state=None, ctc_state=None, ctc_prob=0.0, ctc_candidates=[])
return None, new_hypothesis
Expand current hypothesis with a given beam size
Expand current hypothesis with a given beam size
Expand current hypothesis with a given beam size
def addTopk(self, topi, topv, decoder_state, att_map=None,
                lm_state=None, ctc_state=None, ctc_prob=0.0, ctc_candidates=[]):
        '''Expand current hypothesis with a given beam size'''
        new_hypothesis = []
        term_score = None
        ctc_s, ctc_p = None, None
        beam_size = topi.shape[-1]

        for i in range(beam_size):
            # Detect <eos>
            if topi[i].item() == 1:
                term_score = topv[i].cpu()
                continue

            idxes = self.output_seq[:]     # pass by value
            scores = self.output_scores[:]  # pass by value
            idxes.append(topi[i].cpu())
            scores.append(topv[i].cpu())
            if ctc_state is not None:
                # ToDo: Handle out-of-candidate case.
                idx = ctc_candidates.index(topi[i].item())
                ctc_s = ctc_state[idx, :, :]
                ctc_p = ctc_prob[idx]
            new_hypothesis.append(Hypothesis(decoder_state,
                                             output_seq=idxes, output_scores=scores, lm_state=lm_state,
                                             ctc_state=ctc_s, ctc_prob=ctc_p, att_map=att_map))
        if term_score is not None:
            self.output_seq.append(torch.tensor(1))
            self.output_scores.append(term_score)
            return self, new_hypothesis
        return None, new_hypothesis
def addTopk ( self , topi , topv , decoder_state , att_map = None , lm_state = None , ctc_state = None , ctc_prob = 0.0 , ctc_candidates = [ ] ) : new_hypothesis = [ ] term_score = None ctc_s , ctc_p = None , None beam_size = topi . shape [ - 1 ] for i in range ( beam_size ) : # Detect <eos> if topi [ i ] . item ( ) == 1 : term_score = topv [ i ] . cpu ( ) continue idxes = self . output_seq [ : ] # pass by value scores = self . output_scores [ : ] # pass by value idxes . append ( topi [ i ] . cpu ( ) ) scores . append ( topv [ i ] . cpu ( ) ) if ctc_state is not None : # ToDo: Handle out-of-candidate case. idx = ctc_candidates . index ( topi [ i ] . item ( ) ) ctc_s = ctc_state [ idx , : , : ] ctc_p = ctc_prob [ idx ] new_hypothesis . append ( Hypothesis ( decoder_state , output_seq = idxes , output_scores = scores , lm_state = lm_state , ctc_state = ctc_s , ctc_prob = ctc_p , att_map = att_map ) ) if term_score is not None : self . output_seq . append ( torch . tensor ( 1 ) ) self . output_scores . append ( term_score ) return self , new_hypothesis return None , new_hypothesis