mindspore/docs/api/api_python/ops/mindspore.ops.EditDistance.rst

36 lines
2.0 KiB
ReStructuredText
Raw 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.ops.EditDistance
===========================
.. py:class:: mindspore.ops.EditDistance(normalize=True)
计算Levenshtein编辑距离。它用于测量两个序列的相似性。输入是可变长度的序列由SpaseTensorshypothesis_indices, hypothesis_values, hypothesis_shapetruth_indices, truth_values, truth_shape提供。
.. math::
\operatorname{lev}_{a, b}(i, j)=\left\{\begin{array}{ll}
\max (i, j) \qquad \qquad \qquad \qquad \qquad \quad \ \text { if } \min (i, j)=0 \\
\min \left\{\begin{array}{ll}
\operatorname{lev}_{a, b}(i-1, j)+1 & \\
\operatorname{lev}_{a, b}(i, j-1)+1 & \text { otherwise. } \\
\operatorname{lev}_{a, b}(i-1, j-1)+1_{\left(a_{i} \neq b_{j}\right)}
\end{array}\right. &
\end{array}\right.
其中 :math:`a` 表示预测值, :math:`b` 表示真实值。为了便于理解这里的i和j可以被视为a和b的长度。
参数:
- **normalize** (bool) - 如果为True则编辑距离将按真实值长度标准化。默认值True。
输入:
- **hypothesis_indices** (Tensor) - 预测列表的索引。类型为Tensor数据类型为int64其shape为 :math:`(N,R)`
- **hypothesis_values** (Tensor) - 预测列表的值。类型为Tensor必须是长度为N的一维向量。
- **hypothesis_shape** (Tensor) - 预测列表的shape。类型为Tensor必须是长度为R的向量数据类型为int64。只能是常量。
- **truth_indices** (Tensor) - 真实列表的索引。类型为Tensor数据类型为int64其shape为 :math:`(M,R)`
- **truth_values** (Tensor) - 真实列表的值。类型为Tensor必须是长度为M的一维向量。
- **truth_shape** (Tensor) - 真实列表的shape。类型为Tensor必须是长度为R的向量数据类型为int64。只能是常量。
输出:
Tensor其秩为 `R-1` 数据类型为float32。
异常:
- **TypeError** - 如果 `normalize` 不是bool。