(s_wv, g_wn, g_wvi)
return loss
s_wv:   [bS, 4, mL, 2], 4 stands for maximum # of condition, 2 tands for start & end logits.
    g_wvi:  [ [1, 3, 2], [4,3] ] (when B=2, wn(b=1) = 3, wn(b=2) = 2).
s_wv:   [bS, 4, mL, 2], 4 stands for maximum # of condition, 2 tands for start & end logits.
    g_wvi:  [ [1, 3, 2], [4,3] ] (when B=2, wn(b=1) = 3, wn(b=2) = 2).
s_wv : [ bS 4 mL 2 ] 4 stands for maximum # of condition 2 tands for start & end logits . g_wvi : [ [ 1 3 2 ] [ 4 3 ] ] ( when B = 2 wn ( b = 1 ) = 3 wn ( b = 2 ) = 2 ) .
def Loss_wv_se(s_wv, g_wn, g_wvi):
    """
    s_wv:   [bS, 4, mL, 2], 4 stands for maximum # of condition, 2 tands for start & end logits.
    g_wvi:  [ [1, 3, 2], [4,3] ] (when B=2, wn(b=1) = 3, wn(b=2) = 2).
    """
    loss = 0
    # g_wvi = torch.tensor(g_wvi).to(device)
    for b, g_wvi1 in enumerate(g_wvi):
        # for i_wn, g_wvi11 in enumerate(g_wvi1):

        g_wn1 = g_wn[b]
        if g_wn1 == 0:
            continue
        g_wvi1 = torch.tensor(g_wvi1).to(device)
        g_st1 = g_wvi1[:,0]
        g_ed1 = g_wvi1[:,1]
        # loss from the start position
        loss += F.cross_entropy(s_wv[b,:g_wn1,:,0], g_st1)

        # print("st_login: ", s_wv[b,:g_wn1,:,0], g_st1, loss)
        # loss from the end position
        loss += F.cross_entropy(s_wv[b,:g_wn1,:,1], g_ed1)
        # print("ed_login: ", s_wv[b,:g_wn1,:,1], g_ed1, loss)

    return loss
def Loss_wv_se ( s_wv , g_wn , g_wvi ) : loss = 0 # g_wvi = torch.tensor(g_wvi).to(device) for b , g_wvi1 in enumerate ( g_wvi ) : # for i_wn, g_wvi11 in enumerate(g_wvi1): g_wn1 = g_wn [ b ] if g_wn1 == 0 : continue g_wvi1 = torch . tensor ( g_wvi1 ) . to ( device ) g_st1 = g_wvi1 [ : , 0 ] g_ed1 = g_wvi1 [ : , 1 ] # loss from the start position loss += F . cross_entropy ( s_wv [ b , : g_wn1 , : , 0 ] , g_st1 ) # print("st_login: ", s_wv[b,:g_wn1,:,0], g_st1, loss) # loss from the end position loss += F . cross_entropy ( s_wv [ b , : g_wn1 , : , 1 ] , g_ed1 ) # print("ed_login: ", s_wv[b,:g_wn1,:,1], g_ed1, loss) return loss