Solved by ProGamerGov in post #2 
              
              
                I think I’ve got working with this: 
flattened = input.view(input.size(0), input.size(1), -1)
grams = torch.matmul(flattened, torch.transpose(flattened, 1, 2))
list2 = []
for i in range(input.size(0)):
    list1 = []
    for j in range(input.size(0)):
        if j!=i:
            similarity = sum(to…