def to_llr(x, name="LogLikelihoodRatio"):
''' Convert a matrix of probabilities into log-likelihood ratio
:math:`LLR = log(\\frac{prob(data|target)}{prob(data|non-target)})`
'''
if not is_tensor(x):
x /= np.sum(x, axis=-1, keepdims=True)
x = np.clip(x, 10e-8, 1. - 10e-8)
return np.log(x / (np.cast(1., x.dtype) - x))
else:
with tf.variable_scope(name):
x /= tf.reduce_sum(x, axis=-1, keepdims=True)
x = tf.clip_by_value(x, 10e-8, 1. - 10e-8)
return tf.log(x / (tf.cast(1., x.dtype.base_dtype) - x))
# ===========================================================================
# Speech task metrics
# ===========================================================================
评论列表
文章目录