Cross Entropy Calculator
Free online cross entropy calculator. Enter your values and get instant results with the formula, step-by-step working, a worked example and FAQs — everything runs locally in your browser on Calcton, no signup required.
中文版:交叉熵计算器
原理:交叉熵 H(p,q) = −Σ p_i·log2 q_i,是用分布 q 给真实分布 p 的样本编码所需的平均比特数。它总不小于 H(p),多出来的部分正是 KL 散度——预测越偏离真实,惩罚越大。
步骤:① 输入真实分布与预测分布;② 点击计算;③ 读出交叉熵、熵与两者的差(KL 散度)。
示例:p = (0.5, 0.5)、q = (0.9, 0.1) 时 H(p,q) = 1.736965594166 比特、H(p) = 1、KL = 0.736965594166 比特;q = p 时交叉熵最小且等于 H(p)。
注意事项:q 的每一项必须大于 0——用零概率预测真实会发生的事件,代价是无穷比特,这也是语言模型要平滑处理未知词的原因;两个输入的项数必须相同且各自归一;机器学习里的交叉熵损失与本公式同源,只是常用自然对数(单位奈特)。
相关:KL 散度计算器单独给出分布差异的非对称度量;困惑度计算器把交叉熵换算成「等效分支数」;信息熵计算器是本工具在 q = p 时的特例。
How to use the Cross Entropy Calculator
- Fill in the inputs with your own numbers — every field shows what it expects.
- The result updates instantly as you type; no "Calculate" click needed.
- Read the result card for the main figure, the step-by-step formula, and practical notes.
Frequently asked questions
Is the Cross Entropy Calculator free?
Yes — all math calculators on Calcton are free, with no sign-up required. Your inputs are processed in your browser and never sent to a server.
Is there a Chinese version of this tool?
Yes. Use the Chinese version link above — it is the same calculator with the interface in Simplified Chinese.
References
Formulas and benchmarks used by this calculator follow these published sources.
KevinContent LeadCalcton Editorial Team · Last updated 2026-10-06
Kevin maintains Calcton's formula verification and content: every calculator cites the standard it implements, worked examples are recomputed programmatically, and health benchmarks follow WHO and international guidelines.
Related calculators
More in this category: Math calculators
About math calculators
Free online math calculators for algebra, statistics, number theory and everyday arithmetic — from quadratic equations and matrices to percentages, fractions and prime factorization, each with step-by-step formulas.