(batch_size, text_length, text)
return targets
对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐
    return:
        targets: num_steps+1 * batch_size
对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐
    return:
        targets: num_steps+1 * batch_size
对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐 return : targets : num_steps + 1 * batch_size
def target_txt_decode(batch_size, text_length, text):
    '''
        对target txt每个字符串的开始加上GO，最后加上EOS，并用最长的字符串做对齐
    return:
        targets: num_steps+1 * batch_size
    '''
    nB = batch_size      # batch

    # 将text分离出来
    num_steps = text_length.data.max()
    num_steps = int(num_steps.cpu().numpy())
    targets = torch.ones(nB, num_steps + 2) * 2                 # 用$符号填充较短的字符串, 在最开始加上GO,结束加上EOS_TOKEN
    targets = targets.long().cuda()        # 用
    start_id = 0
    for i in range(nB):
        targets[i][0] = GO    # 在开始的加上开始标签
        targets[i][1:text_length.data[i] + 1] = text.data[start_id:start_id+text_length.data[i]]       # 是否要加1
        targets[i][text_length.data[i] + 1] = EOS_TOKEN         # 加上结束标签
        start_id = start_id+text_length.data[i]                 # 拆分每个目标的target label，为：batch×最长字符的numel
    targets = Variable(targets.transpose(0, 1).contiguous())
    return targets
def target_txt_decode ( batch_size , text_length , text ) : nB = batch_size # batch # 将text分离出来 num_steps = text_length . data . max ( ) num_steps = int ( num_steps . cpu ( ) . numpy ( ) ) targets = torch . ones ( nB , num_steps + 2 ) * 2 # 用$符号填充较短的字符串, 在最开始加上GO,结束加上EOS_TOKEN targets = targets . long ( ) . cuda ( ) # 用 start_id = 0 for i in range ( nB ) : targets [ i ] [ 0 ] = GO # 在开始的加上开始标签 targets [ i ] [ 1 : text_length . data [ i ] + 1 ] = text . data [ start_id : start_id + text_length . data [ i ] ] # 是否要加1 targets [ i ] [ text_length . data [ i ] + 1 ] = EOS_TOKEN # 加上结束标签 start_id = start_id + text_length . data [ i ] # 拆分每个目标的target label，为：batch×最长字符的numel targets = Variable ( targets . transpose ( 0 , 1 ) . contiguous ( ) ) return targets