From ba1f308b1f9b2bacdee4f829b87c9fcd5e7a5c9f Mon Sep 17 00:00:00 2001 From: nlpfun Date: Tue, 30 Nov 2021 08:31:57 +0800 Subject: [PATCH] Update bert_align.py --- bin/bert_align.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/bert_align.py b/bin/bert_align.py index 9234631..65be58b 100644 --- a/bin/bert_align.py +++ b/bin/bert_align.py @@ -196,7 +196,8 @@ def second_pass_align(src_vecs, def second_back_track(i, j, b, search_path, a_types): alignment = [] - while ( i !=0 and j != 0 ): + #while ( i !=0 and j != 0 ): + while ( 1 ): j_offset = j - search_path[i][0] a = b[i][j_offset] s = a_types[a][0] @@ -207,8 +208,9 @@ def second_back_track(i, j, b, search_path, a_types): i = i-s j = j-t - - return alignment[::-1] + + if i == 0 and j == 0: + return alignment[::-1] @nb.jit(nopython=True, fastmath=True, cache=True) def get_score(src_v, tgt_v, @@ -306,7 +308,8 @@ def first_back_track(i, j, b, search_path, a_types): alignment: list of tuples for 1-1 alignments. """ alignment = [] - while ( i !=0 and j != 0 ): + #while ( i !=0 and j != 0 ): + while ( 1 ): j_offset = j - search_path[i][0] a = b[i][j_offset] s = a_types[a][0] @@ -316,8 +319,9 @@ def first_back_track(i, j, b, search_path, a_types): i = i-s j = j-t - - return alignment[::-1] + + if i == 0 and j == 0: + return alignment[::-1] @nb.jit(nopython=True, fastmath=True, cache=True) def first_pass_align(src_len,