Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于torch.mean(torch.sum(loss))的问题 #2

Open
ezio0218 opened this issue Jun 10, 2022 · 6 comments
Open

关于torch.mean(torch.sum(loss))的问题 #2

ezio0218 opened this issue Jun 10, 2022 · 6 comments

Comments

@ezio0218
Copy link

您好,我主要想问一下为什么在这个地方
image
要加torch.mean,打印出来好像都是一样的呀。sum的时候好像就已经没有维度了

@Forrest-Stone
Copy link
Owner

hello, sum(loss) 里面的loss跟预测的target个数有关

@ezio0218
Copy link
Author

image
image
感谢您的回复,就以实例中的target和neg都是2,batch_size为4096为例。pos_score和neg_score的维度此时都是[4096,2],所以您做torch.mean(torch.sum())的想法是希望两个target的loss相加然后除以batch_size的大小吗?如果直接求mean()是可以的嘛

@ezio0218
Copy link
Author

主要是我看伯乐库中对于BPR的计算是直接求的mean:
image
当然一般情况下带有label的数据target大小都是1,在您的数据场景下target会大于1

@Forrest-Stone
Copy link
Owner

image image 感谢您的回复,就以实例中的target和neg都是2,batch_size为4096为例。pos_score和neg_score的维度此时都是[4096,2],所以您做torch.mean(torch.sum())的想法是希望两个target的loss相加然后除以batch_size的大小吗?如果直接求mean()是可以的嘛

hello,主要是涉及到batch_size是否加入计算,我觉得都是可以的

@ezio0218
Copy link
Author

好的 非常感谢及时的回复!最后想问一下,如果想用pyg库中写好的gnn layer来替换magnn中的GNNCell模块功能是可行的吗

@Forrest-Stone
Copy link
Owner

是可行的,功能对应着就可以

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants