End detection. described in Eq. (50) of S. Watanabe et al "Hybrid CTC/Attention Architecture for End-to-End Speech Recognition" :param ended_hyps: :param i: :param M: :param D_end: :return:
(ended_hyps, i, M=3, D_end=np.log(1 * np.exp(-10)))
| 16 | |
| 17 | |
| 18 | def end_detect(ended_hyps, i, M=3, D_end=np.log(1 * np.exp(-10))): |
| 19 | """End detection. |
| 20 | |
| 21 | described in Eq. (50) of S. Watanabe et al |
| 22 | "Hybrid CTC/Attention Architecture for End-to-End Speech Recognition" |
| 23 | |
| 24 | :param ended_hyps: |
| 25 | :param i: |
| 26 | :param M: |
| 27 | :param D_end: |
| 28 | :return: |
| 29 | """ |
| 30 | if len(ended_hyps) == 0: |
| 31 | return False |
| 32 | count = 0 |
| 33 | best_hyp = sorted(ended_hyps, key=lambda x: x["score"], reverse=True)[0] |
| 34 | for m in six.moves.range(M): |
| 35 | # get ended_hyps with their length is i - m |
| 36 | hyp_length = i - m |
| 37 | hyps_same_length = [x for x in ended_hyps if len(x["yseq"]) == hyp_length] |
| 38 | if len(hyps_same_length) > 0: |
| 39 | best_hyp_same_length = sorted(hyps_same_length, key=lambda x: x["score"], reverse=True)[ |
| 40 | 0 |
| 41 | ] |
| 42 | if best_hyp_same_length["score"] - best_hyp["score"] < D_end: |
| 43 | count += 1 |
| 44 | |
| 45 | if count == M: |
| 46 | return True |
| 47 | else: |
| 48 | return False |
| 49 | |
| 50 | |
| 51 | # TODO(takaaki-hori): add different smoothing methods |
no test coverage detected
searching dependent graphs…