(logits, label, lengths)
return loss
Args
        logits: shape (b_sz, tstp, c_sz)
        label: shape (b_sz, tstp)
        lengths: shape(b_sz)
    Return
        loss: A scalar tensor, mean error
Args
        logits: shape (b_sz, tstp, c_sz)
        label: shape (b_sz, tstp)
        lengths: shape(b_sz)
    Return
        loss: A scalar tensor, mean error
Args logits : shape ( b_sz tstp c_sz ) label : shape ( b_sz tstp ) lengths : shape ( b_sz ) Return loss : A scalar tensor mean error
def seq_loss(logits, label, lengths):
    """
    Args
        logits: shape (b_sz, tstp, c_sz)
        label: shape (b_sz, tstp)
        lengths: shape(b_sz)
    Return
        loss: A scalar tensor, mean error
    """

    loss_all = tf.nn.sparse_softmax_cross_entropy_with_logits(  # shape(b_sz, tstp), step level
        logits=logits, labels=label, name='seq_loss')
    loss_avg = reduce_avg(loss_all, lengths, dim=1)    # shape(b_sz) example level
    loss = tf.reduce_mean(loss_avg)
    return loss
def seq_loss ( logits , label , lengths ) : loss_all = tf . nn . sparse_softmax_cross_entropy_with_logits ( # shape(b_sz, tstp), step level logits = logits , labels = label , name = 'seq_loss' ) loss_avg = reduce_avg ( loss_all , lengths , dim = 1 ) # shape(b_sz) example level loss = tf . reduce_mean ( loss_avg ) return loss