Okay thank you so much for your answer in fact I just found a problem with this method according to my problem
In fact I don’t want to look at the latent vector of the current input.
I have different classes let say for examples animals : cats, dogs and birds.
If my current input is a cat: cat_i and I have n cats in my dataset: {cat_1, cat_2, …, cat_n}.
I want the latent vector to learn the distribution among the cats, the dogs and the birds separately.
So I would like to code the Loss this way:
Loss = self.criterion(current_reconstructed_cat_i, cat_i) 
+ sum{for j=1 to n, j!=i} some_function(current_latent_vector_of_cat_j, current_latent_vector_of_cat_i)

current_latent_vector_of_cat_j is the current pass forward stopped to the latent_vector.
Best,
Didier