output = [cos(input1.[:, :, idx, :].unsqueeze(0).unsqueeze(1), input2)) for idx in range(10)] should work.
However I am not sure it makes sense to compute the cosine similarity of a subset of the layer.