def get_edit_distance(hyp_arr, truth_arr, normalize, level):
''' calculate edit distance
This is very universal, both for cha-level and phn-level
'''
graph = tf.Graph()
with graph.as_default():
truth = tf.sparse_placeholder(tf.int32)
hyp = tf.sparse_placeholder(tf.int32)
editDist = tf.reduce_sum(tf.edit_distance(hyp, truth, normalize=normalize))
with tf.Session(graph=graph) as session:
truthTest = list_to_sparse_tensor(truth_arr, level)
hypTest = list_to_sparse_tensor(hyp_arr, level)
feedDict = {truth: truthTest, hyp: hypTest}
dist = session.run(editDist, feed_dict=feedDict)
return dist
评论列表
文章目录