簡體   English   中英

如何理解張量流中的'viterbi_decode'

[英]How to understand the 'viterbi_decode' in tensorflow

HMM中使用的傳統維特比算法具有起始概率矩陣( 維特比算法wiki ),但是張量中的維特比 解碼參數僅需要轉移概率矩陣發射概率矩陣 怎么理解呢?

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中的維特比算法不需要初始概率矩陣,因為它通過為所有狀態賦予零概率來開始解碼。

這意味着它從狀態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.

然后

log_likelihood , transition_params = tf.contrib.crf.crf_log_likelihood(logits,labels_a,sequence_len)

#return of crf log_likelihood function

# log_likelihood: A scalar containing the log-likelihood of the given sequence of tag indices.

# transition_params: A [num_tags, num_tags] transition matrix. 

# This is either provided by the caller or created in this function.

現在我們可以計算維特比分數:

# score: A [seq_len, num_tags] matrix of unary potentials.
# transition_params: A [num_tags, num_tags] matrix of binary potentials.

筆記本鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM