Hi, I want to implement a CopyNet with pytorch. But I encounter a problem now.
In tensorflow, there is scatter_nd operation

indices = tf.constant([0,3])
updates = tf.constant([0.2,0.6])
scatter = tf.scatter_nd(indices, updates, shape=4)
print scatter
[0.2 , 0 , 0 , 0.6]


as you can see, the index in indices fill the corresponding value in updates.
But I don’t know how to achieve this.
I try use torch.cuda.sparse.FloatTensor(indices,updates,size) replace, but it seems can’t backward the gradient.
My whole code as follow, can train, but p_gen become 1 gradually, so I doubt there is no gradient back for new_atten_prob

    p_gen = p_gen.unsqueeze(-1)
    normal_output_prob = p_gen.expand_as(output_prob) * output_prob
    normal_atten_prob = (1 - p_gen).expand_as(atten_prob) * atten_prob
    new_atten_list = []
    for input_token, atten_prob_token in zip(input.split(1), normal_atten_prob.split(1)):
        atten_prob_token = atten_prob_token.squeeze(0)
        new_atten_list.append(torch.cuda.sparse.FloatTensor(
            input_token.data, atten_prob_token.data, torch.Size([normal_output_prob.size(1)+30])).to_dense())
    new_atten_prob = torch.stack(new_atten_list, dim=0)
    new_normal_prob = torch.cat([normal_output_prob,Variable(torch.zeros(normal_output_prob.size(0),30).cuda())],-1)
    prob = (Variable(new_atten_prob,requires_grad=True) + new_normal_prob)
    return prob