easezyc / Multitask-Recommendation-Library

MTReclib provides a PyTorch implementation of multi-task recommendation models and common datasets.
MIT License
277 stars 46 forks source link

ple 实现有问题 #4

Closed wolaiye1010 closed 1 year ago

wolaiye1010 commented 1 year ago
    task_fea = [emb for i in range(self.task_num + 1)]
    for i in range(self.layers_num):
        for j in range(self.task_num + 1):
            fea = torch.cat([self.expert[i][index](task_fea[j]).unsqueeze(1) for index in self.task_expert_index[j]], dim = 1)

上面这一行代码会导致,shareExpert 的输入是上一层的task的输出,第一层的时候没有问题,第二层就会有问题,如下图红线所示。

            gate_value = self.gate[i][j](task_fea[j]).unsqueeze(1)
            task_fea[j] = torch.bmm(gate_value, fea).squeeze(1)

image

easezyc commented 1 year ago

不太明白你说的是什么问题,shareExpert的输入不就应该是上一层所有shared expert以及specific expert的输出吗

wolaiye1010 commented 1 year ago

@easezyc , 我描述有问题,实际的问题点就是我红线画的,第一层的每个specificExpert的输出,应该只输入到相应的下一层的specific task,share expert的输出到share expert,但现在的实现变成了我红线所画的流程。

wolaiye1010 commented 1 year ago

@easezyc ,我可以改下,发个pr你看下

easezyc commented 1 year ago

感觉是你理解错了,红线才是对的,你看这个代码,也是这种实现,不过他只有一层 https://github.com/huangjunheng/recommendation_model/blob/master/mmoe_model/PLE.py

easezyc commented 1 year ago

@wolaiye1010 It is worth noting that the selected matrix of the shared module in PLE is slightly different from task-specific modules, as it consists of all shared experts and task-specific experts in this layer. 论文原文,红线才是对的

wolaiye1010 commented 1 year ago

@easezyc ,"It is worth noting that the selected matrix of the shared module in PLE is slightly different from task-specific modules, as it consists of all shared experts and task-specific experts in this layer." 这句话的意思不是红线相连,而是shareExpert 的输出是由shareExpert 的gate混合 上一层 所有taskSpecific +expert的输出

wolaiye1010 commented 1 year ago

@easezyc , 可以看下这个 高star的tf的开源实现 https://github.com/shenweichen/DeepCTR/blob/master/deepctr/models/multitask/ple.py 是没有红线部分的,每个task的输入就是上一层的混合后 的task的输出,而且论文里的结构图片也是这么画的

wolaiye1010 commented 1 year ago

感觉是你理解错了,红线才是对的,你看这个代码,也是这种实现,不过他只有一层 https://github.com/huangjunheng/recommendation_model/blob/master/mmoe_model/PLE.py

这个代码只实现了单层的cgc 网络,没有实现后面的层。

easezyc commented 1 year ago

@wolaiye1010 我get了我的代码的问题在哪了,你的commit我已经merge进去了,感谢你的贡献

wolaiye1010 commented 1 year ago

@easezyc , 已测试没有问题,pull request里有test方法

easezyc commented 1 year ago

@wolaiye1010 也再麻烦你确认一下你提交的代码是否能跑通我给的这几个数据集(我最近没什么时间来测试),看看这个表格里的实验结果(3次重复实验)是否需要更正一下,再次感谢你的贡献 1664169309597