(i_nlu, l_n, hS, num_hidden_layers, all_encoder_layer, num_out_layers_n)
return wemb_n
Get the representation of each tokens.
Get the representation of each tokens.
Get the representation of each tokens .
def get_wemb_n(i_nlu, l_n, hS, num_hidden_layers, all_encoder_layer, num_out_layers_n):
    """
    Get the representation of each tokens.
    """
    bS = len(l_n)
    l_n_max = max(l_n)
    wemb_n = torch.zeros([bS, l_n_max, hS * num_out_layers_n]).to(device)
    for b in range(bS):
        # [B, max_len, dim]
        # Fill zero for non-exist part.
        l_n1 = l_n[b]
        i_nlu1 = i_nlu[b]
        for i_noln in range(num_out_layers_n):
            i_layer = num_hidden_layers - 1 - i_noln
            st = i_noln * hS
            ed = (i_noln + 1) * hS
            wemb_n[b, 0:(i_nlu1[1] - i_nlu1[0]), st:ed] = all_encoder_layer[i_layer][b, i_nlu1[0]:i_nlu1[1], :]
    return wemb_n
def get_wemb_n ( i_nlu , l_n , hS , num_hidden_layers , all_encoder_layer , num_out_layers_n ) : bS = len ( l_n ) l_n_max = max ( l_n ) wemb_n = torch . zeros ( [ bS , l_n_max , hS * num_out_layers_n ] ) . to ( device ) for b in range ( bS ) : # [B, max_len, dim] # Fill zero for non-exist part. l_n1 = l_n [ b ] i_nlu1 = i_nlu [ b ] for i_noln in range ( num_out_layers_n ) : i_layer = num_hidden_layers - 1 - i_noln st = i_noln * hS ed = ( i_noln + 1 ) * hS wemb_n [ b , 0 : ( i_nlu1 [ 1 ] - i_nlu1 [ 0 ] ) , st : ed ] = all_encoder_layer [ i_layer ] [ b , i_nlu1 [ 0 ] : i_nlu1 [ 1 ] , : ] return wemb_n