MCPcopy Create free account
hub / github.com/modelscope/FunASR / post_process

Method post_process

funasr/models/transformer/search.py:403–449  ·  view source on GitHub ↗

Perform post-processing of beam search iterations. Args: i (int): The length of hypothesis tokens. maxlen (int): The maximum length of tokens in beam search. maxlenratio (int): The maximum length ratio in beam search. running_hyps (List[Hypoth

(
        self,
        i: int,
        maxlen: int,
        maxlenratio: float,
        running_hyps: List[Hypothesis],
        ended_hyps: List[Hypothesis],
    )

Source from the content-addressed store, hash-verified

401 return nbest_hyps
402
403 def post_process(
404 self,
405 i: int,
406 maxlen: int,
407 maxlenratio: float,
408 running_hyps: List[Hypothesis],
409 ended_hyps: List[Hypothesis],
410 ) -> List[Hypothesis]:
411 """Perform post-processing of beam search iterations.
412
413 Args:
414 i (int): The length of hypothesis tokens.
415 maxlen (int): The maximum length of tokens in beam search.
416 maxlenratio (int): The maximum length ratio in beam search.
417 running_hyps (List[Hypothesis]): The running hypotheses in beam search.
418 ended_hyps (List[Hypothesis]): The ended hypotheses in beam search.
419
420 Returns:
421 List[Hypothesis]: The new running hypotheses.
422
423 """
424 logging.debug(f"the number of running hypotheses: {len(running_hyps)}")
425 if self.token_list is not None:
426 logging.debug(
427 "best hypo: " + "".join([self.token_list[x] for x in running_hyps[0].yseq[1:]])
428 )
429 # add eos in the final loop to avoid that there are no ended hyps
430 if i == maxlen - 1:
431 logging.info("adding <eos> in the last position in the loop")
432 running_hyps = [
433 h._replace(yseq=self.append_token(h.yseq, self.eos)) for h in running_hyps
434 ]
435
436 # add ended hypotheses to a final list, and removed them from current hypotheses
437 # (this will be a problem, number of hyps < beam)
438 remained_hyps = []
439 for hyp in running_hyps:
440 if hyp.yseq[-1] == self.eos:
441 # e.g., Word LM needs to add final <eos> score
442 for k, d in chain(self.full_scorers.items(), self.part_scorers.items()):
443 s = d.final_score(hyp.states[k])
444 hyp.scores[k] += s
445 hyp = hyp._replace(score=hyp.score + self.weights[k] * s)
446 ended_hyps.append(hyp)
447 else:
448 remained_hyps.append(hyp)
449 return remained_hyps

Callers 1

forwardMethod · 0.95

Calls 2

append_tokenMethod · 0.95
final_scoreMethod · 0.45

Tested by

no test coverage detected