mindspore2022/docs/api/api_python/nn/mindspore.nn.Perplexity.rst

47 lines
1.5 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.Perplexity
===========================
.. py:class:: mindspore.nn.Perplexity(ignore_label=None)
计算困惑度perplexity。困惑度是衡量一个概率分布或语言模型好坏的标准。低困惑度表明语言模型可以很好地预测样本。计算方式如下
.. math::
PP(W)=P(w_{1}w_{2}...w_{N})^{-\frac{1}{N}}=\sqrt[N]{\frac{1}{P(w_{1}w_{2}...w_{N})}}
其中 :math:`w` 代表语料库中的单词.
**参数:**
- **ignore_label** (int) - 计数时要忽略的无效标签的索引。如果设置为None它将包括所有条目。默认值None。
.. py:method:: clear()
内部评估结果清零。
.. py:method:: eval()
返回当前评估结果。
**返回:**
numpy.float64计算得到的困惑度结果。
**异常:**
- **RuntimeError** - 样本量为0。
.. py:method:: update(*inputs)
使用 `preds``labels` 更新内部评估结果。
**参数:**
- **inputs** - 输入 `preds``labels``preds``labels` 是Tensor、list或numpy.ndarray。 `preds` 是预测值, `labels` 是数据的标签。 `preds``labels` 的shape都是 :math:`(N, C)`
**异常:**
- **ValueError** - 输入数量不是2。
- **RuntimeError** - 预测值和标签的长度不同。
- **RuntimeError** - 预测值和标签的shape不同。