JackGao09:

words[j] = words[j] * weight[j]


Note completely sure, but possibly this operation is modifying the Tensor in-place and thus losing the ability for performing backprop correctly. Possibly you can save the result of words[j] * weight[j] in a different place?