lpworld / DASL

12 stars 2 forks source link

A simple issue of the orthogonal_loss #3

Open hulkima opened 2 years ago

hulkima commented 2 years ago

Hello, I'm a little confused about the loss of the orthogonal matrix in your paper and the corresponding code. Is it just a constraint function on user representation between the source domain and target domain and not really used in the projection process? I found similar code for the pytorch version in your DDTCDR repository, but I'm not sure how to use it. Have you ever realized the loss function in the pytorch version? If not, could you tell me how should I finish it? Thank you!

lpworld commented 2 years ago

Hello! Thanks for your interest in our project. The orthogonal loss is constructed through the Gram–Schmidt process, as explained in the following code in DDTCDR:

    for name, param in self.modelA.bridge.named_parameters():
        if 'bias' not in name:
            param_flat = param.view(param.shape[0], -1)
            sym = torch.mm(param_flat, torch.t(param_flat))
            sym -= torch.eye(param_flat.shape[0])
            orth_loss_A = orth_loss_A + (reg * sym.abs().sum())

To use it you only need to backpropagate the orth_loss accordingly. Regarding the other problem you have mentioned in the other issue, the codes are still valid in this repository but we need to update the numbers in the Table as we have made an error when computing the AUC & HR@10 in recommendations. Sorry for the confusion.

hulkima commented 2 years ago

Hi! Thank you for your quick reply! I also found this part of the code in the repository of DDTCDR, but I'm not sure how to modify it. Can I just copy the following code in DDTCDR for the pytorch version of DASL?

` self.bridge = torch.nn.Linear(hidden_size // 2, hiddensize // 2) torch.nn.init.orthogonal(self.bridge.weight)

def calculate_orthogonal_loss(self, u_2):
    for name, param in self.bridge.named_parameters():
        if 'bias' not in name:
            param_flat = param.view(param.shape[0], -1)
            sym = torch.mm(param_flat, torch.t(param_flat))
            sym -= torch.eye(param_flat.shape[0])
            orth_loss_A = reg * sym.abs().sum()

`

You don't seem to use the ”self.bridge“ to map in DASL, but just to constrain the information transfer process. If I follow the DDTCDR method directly, will I introduce a useless information? I modified it according to my understanding and the code in the two repositories of DASL and DDTCDR. I wonder whether it is correct?

` self.bridge = torch.nn.Linear(hidden_size // 2, hiddensize // 2) torch.nn.init.orthogonal(self.bridge.weight)

def calculate_orth_loss(self, u_2):
    user_emb_2 = self.user_emb_w_2(u_2) # user2在target域的weight
    user_emb_21 = self.user_emb_w_1(u_2) # user2在source域的weight
    user_emb_2_map = self.bridge(user_emb_2)
    orth_loss_A = torch.nn.CosineSimilarity(dim=1, eps=1e-6)(user_emb_2_map, user_emb_21)

    for name, param in self.bridge.named_parameters():
        if 'bias' not in name:
            param_flat = param.view(param.shape[0], -1)
            sym = torch.mm(param_flat, torch.t(param_flat))
            sym -= torch.eye(param_flat.shape[0])
            orth_loss_A += reg * sym.abs().sum()

`

I am not familiar with TensorFlow, hope to get your help, thank you!


I'm really sorry. I was going to make it more organized, but it seems to be worse.

lpworld commented 2 years ago

Yes I think what you have right now is fine. Please let me know if you encounter any problems!

hulkima commented 2 years ago

Thank you very much for your help. I'm rewriting your code into the pytoch framework. If there's something I don't understand, I hope I can get your help.