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

交叉熵损失函数PI文档问题 #5873

Open
changzipeng opened this issue May 9, 2023 · 0 comments
Open

交叉熵损失函数PI文档问题 #5873

changzipeng opened this issue May 9, 2023 · 0 comments

Comments

@changzipeng
Copy link

文档链接&描述 Document Links & Description

https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/cross_entropy_cn.html#daimashili
您好,想咨询一个问题,在计算交叉熵损失函数时。假如针对的分类问题是一个3分类的问题,假如样本目前只有1个,假如模型输出三个预测值[0.4, 0.6, 0.8],软标签为[0, 1, 0],在输入到交叉熵损害函数后,use_softmax默认是true,因此首先对输入数据做softmax,得到logits=[0.27,0.33,0.4],之后计算loss,loss = - 1 * (0.33 - log(exp(0.27)) + exp(0.33)) + exp(0.4))) = -0.33 + log(4.19) = 1.1;这是通过文档定义的方式计算得到的结果;
通过交叉熵损失函数实际定义得到结果:
y1 = exp(0.4) / (exp(0.4)+exp(0.6)+exp(0.8));
y2 = exp(0.6) / (exp(0.4)+exp(0.6)+exp(0.8));
y3 = exp(0.8) / (exp(0.4)+exp(0.6)+exp(0.8));
t1 = 0; t2 = 1; t3 =0;
计算交叉熵损失:L = -(log(1-y1) + log(y2) + log(1-y3)) = 1.93
为什么交叉熵损失的计算方式要按照文档中定义的方式来呢,因为按照交叉熵最原始的定义,文档的计算结果和交叉熵定义的计算结果并不一致。

请提出你的建议/提个PR修复这个问题 Please give your suggestion/update a PR to fix it

No response

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

1 participant