How to implement dot product loss for similarity task

I am trying to implement dual-shared encoder which requires dot product loss between the source and the target representations

P.S. I have tried to use the nn.CosineEmbeddingLoss() but the loss returned is close to zero.