parameters: (self, tags_for_rank, result, words_length)
return_statement: return batch_out
docstring: 将RANK模型输出的Tensor转为明文
docstring_summary: 将RANK模型输出的Tensor转为明文
docstring_tokens: 将RANK模型输出的Tensor转为明文
function: def parse_result(self, tags_for_rank, result, words_length):
          """将RANK模型输出的Tensor转为明文"""
          offset_list = result.lod[0]
          rank_weight = result.data.int64_data()
          batch_size = len(offset_list) - 1
  
          batch_out = []
          for sent_index in range(batch_size):
              begin, end = offset_list[sent_index], offset_list[sent_index + 1]
  
              tags = tags_for_rank[sent_index]
              word_length = words_length[sent_index]
              weight = rank_weight[begin:end]
  
              # 重新填充被省略的单词的char部分
              for current in range(len(word_length)-1, -1, -1):
                  for offset in range(1, word_length[current]):
                      weight.insert(current + offset, weight[current])
  
              weight_out = []
              for ind, tag in enumerate(tags):
                  if len(weight_out) == 0 or tag.endswith("B") or tag.endswith("S"):
                      weight_out.append(weight[ind])
                      continue
                  weight_out[-1] = max(weight_out[-1], weight[ind])
  
              batch_out.append(weight_out)
          return batch_out
function_tokens: def parse_result ( self , tags_for_rank , result , words_length ) : offset_list = result . lod [ 0 ] rank_weight = result . data . int64_data ( ) batch_size = len ( offset_list ) - 1 batch_out = [ ] for sent_index in range ( batch_size ) : begin , end = offset_list [ sent_index ] , offset_list [ sent_index + 1 ] tags = tags_for_rank [ sent_index ] word_length = words_length [ sent_index ] weight = rank_weight [ begin : end ] # 重新填充被省略的单词的char部分 for current in range ( len ( word_length ) - 1 , - 1 , - 1 ) : for offset in range ( 1 , word_length [ current ] ) : weight . insert ( current + offset , weight [ current ] ) weight_out = [ ] for ind , tag in enumerate ( tags ) : if len ( weight_out ) == 0 or tag . endswith ( "B" ) or tag . endswith ( "S" ) : weight_out . append ( weight [ ind ] ) continue weight_out [ - 1 ] = max ( weight_out [ - 1 ] , weight [ ind ] ) batch_out . append ( weight_out ) return batch_out