(logits_matrix, index_2_idiom)
return results
从矩阵中计算全局概率最大的序列
从矩阵中计算全局概率最大的序列
从矩阵中计算全局概率最大的序列
def logits_matrix_to_array(logits_matrix, index_2_idiom):
    """从矩阵中计算全局概率最大的序列"""
    logits_matrix = np.array(logits_matrix)
    logits_matrix = np.transpose(logits_matrix)
    tmp = []
    for i, row in enumerate(logits_matrix):
        for j, col in enumerate(row):
            tmp.append((i, j, col))
    else:
        choice = set(range(i + 1))
        blanks = set(range(j + 1))
    tmp = sorted(tmp, key=lambda x: x[2], reverse=True)
    results = []
    for i, j, v in tmp:
        if (j in blanks) and (i in choice):
            results.append((i, j))
            blanks.remove(j)
            choice.remove(i)
    results = sorted(results, key=lambda x: x[1], reverse=False)
    results = [[index_2_idiom[j], i] for i, j in results]
    return results
def logits_matrix_to_array ( logits_matrix , index_2_idiom ) : logits_matrix = np . array ( logits_matrix ) logits_matrix = np . transpose ( logits_matrix ) tmp = [ ] for i , row in enumerate ( logits_matrix ) : for j , col in enumerate ( row ) : tmp . append ( ( i , j , col ) ) else : choice = set ( range ( i + 1 ) ) blanks = set ( range ( j + 1 ) ) tmp = sorted ( tmp , key = lambda x : x [ 2 ] , reverse = True ) results = [ ] for i , j , v in tmp : if ( j in blanks ) and ( i in choice ) : results . append ( ( i , j ) ) blanks . remove ( j ) choice . remove ( i ) results = sorted ( results , key = lambda x : x [ 1 ] , reverse = False ) results = [ [ index_2_idiom [ j ] , i ] for i , j in results ] return results