The main idea is that i want to minimize the cosine distance and also have a l2-norm of 1.
So there are 2 stages:
output is a batch of vectors, so at first i calculate the l2-norm of each vector:

output1_normed = output1.norm(p=2, dim=1)

and then i want to put a constraint that each norm should be 1 so i use:

loss_func2 = nn.L1Loss().cuda()
target = Variable(torch.ones(len(outputs), 1)).cuda()
loss2 = loss_func2(outputs_normed, targets)

So please notice that i am calculating:
| 1 - l2_norm(output) |
So i actually want that all of the vectors that are in output will be a unit vector. for this reason i mix the l2 and l1