There’s no built in method that can do that. It seems weird to me that you want the desired results to have columns of (word_idx, sum), because the first column is integral, while the other is floating point. Tensors are always homogenous. I don’t think there’s a method for that in any of the numerical packages. You’ll have to process the tensors using your own Python code. If you want to make it differentiable, you can create your own autograd Function 33.