Tensorflow 如何理解';维特比解码&x27;在张量流中
HMM中使用的传统viterbi算法有一个开始概率矩阵(),而tensorflow中的viterbi_解码参数只需要转移概率矩阵和发射概率矩阵。如何理解它Tensorflow 如何理解';维特比解码&x27;在张量流中,tensorflow,viterbi,Tensorflow,Viterbi,HMM中使用的传统viterbi算法有一个开始概率矩阵(),而tensorflow中的viterbi_解码参数只需要转移概率矩阵和发射概率矩阵。如何理解它 def viterbi_decode(score, transition_params): """Decode the highest scoring sequence of tags outside of TensorFlow. This should only be used at test time. Args:
def viterbi_decode(score, transition_params):
"""Decode the highest scoring sequence of tags outside of
TensorFlow.
This should only be used at test time.
Args:
score: A [seq_len, num_tags] matrix of unary potentials.
transition_params: A [num_tags, num_tags] matrix of binary potentials.
Returns:
viterbi: A [seq_len] list of integers containing the highest scoring tag
indicies.
viterbi_score: A float containing the score for the Viterbi
sequence.
"""
Tensorflow中的viterbi算法不需要初始概率矩阵,因为它通过为所有状态提供零概率来开始解码 这意味着它从状态0开始
您可以查看实现。我已经创建了关于tensorflow的viterbi算法的完整详细教程,示例如下: 假设您的数据如下所示:
# logits : A [batch_size, max_seq_len, num_tags] tensor of unary potentials to use as input to the CRF layer.
# labels_a : A [batch_size, max_seq_len] matrix of tag indices for which we compute the log-likelihood.
# sequence_len : A [batch_size] vector of true sequence lengths.
然后
现在我们可以计算维特比分数:
# score: A [seq_len, num_tags] matrix of unary potentials.
# transition_params: A [num_tags, num_tags] matrix of binary potentials.
# score: A [seq_len, num_tags] matrix of unary potentials.
# transition_params: A [num_tags, num_tags] matrix of binary potentials.