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

Protonet #49

Closed
ch-control opened this issue Sep 21, 2022 · 3 comments
Closed

Protonet #49

ch-control opened this issue Sep 21, 2022 · 3 comments

Comments

@ch-control
Copy link

你好,我在Protonet网络中计算距离矩阵时乘以了0.01,发现训练准确率提升了,请问这个是正常的吗?还是说最终的准确率与距离的数量级也有关系。
"euclidean": lambda x, y: -0.01*torch.sum(
torch.pow(x.unsqueeze(2) - y.unsqueeze(1), 2),
dim=3,

@yangcedrus
Copy link
Contributor

yangcedrus commented Sep 21, 2022

你好,这种在计算损失之前在距离上乘以一个数,就是有些方法会用的温度。

这些方法会用温度来控制距离分布的熵。乘上0.01后,pytorch实际进行交叉熵计算的是经过softmax的tensor。softmax的结果会受到温度影响,但是和不用温度结果相比,不会有数量级或者大小关系的变化,只会使得每个类分类结果的分布平缓或者尖锐。

你所做的乘以0.01,就是使用值为100的温度。至于温度对方法的影响,这个对不同的方法是不同的,因此准确率提升或者下降都是有可能的。

@ch-control
Copy link
Author

感谢回复,那我可不可以理解为距离的数量级对模型最终的准确率会有影响,那么假如我对距离度量进行了改进导致最终距离的数量级变小,我怎么能够确定最终模型准确率的提升是因为我的改进方法还是因为数量级的变化?

@yangcedrus
Copy link
Contributor

由于计算交叉熵之前需要先使用softmax对距离进行处理,因此乘上系数不能简单理解为改变了距离的数量级,系数最主要的所用是改变softmax的输出分布。

如果是只是对ProtoNet的欧式距离乘上这种系数,并不能称得上是对距离度量的改进,而是在距离上应用了温度这个技巧。
如果是对其他你所提出的距离度量进行分析,需要进行消融,尝试去掉温度或者换一个带相同温度的其他度量来进行消融实验,以此来验证是温度还是距离度量的作用。
深度学习中的temperature parameter
交叉熵的计算

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