PaddlePaddle / PaddlePaddle/docs

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

Open
#5,873 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
284
Forks
906
PR merge metrics
No merged PRs in 30d

Description

文档链接&描述 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked cross_entropy_cn.html example and compare its documented calculation with the soft-label values and alternative calculation supplied in the issue. Check the API's stated inputs and defaults, then determine whether the wording or example is incorrect. Done means the documentation clearly explains the applicable formula and matches the function's behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, machine-learning
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.