CRF学习笔记

惯例,首先导入TensorFlow,

import tensorflow as tf

tensorflow 中的 CRF

tf.contrib.crf.crf_log_likelihood(inputs=, tag_indices=, sequence_lengths=, transition_params=None)

Computes the log-likelihood of tag sequences in a CRF.

Args:

  • iputs: A [batch_size, max_seq_len, num_tags] tensor of unary potentials to use as input to the CRF layer.
  • tag_indices: A [batch_size, max_seq_len] matrix of tag indices for which we compute the log-likelihood.
  • sequence_lengths: A [batch_size] vector of true sequence lengths.
  • transition_params: A [num_tags, num_tags] transition matrix, if available.

Returns:

  • log_likelihood: A [batch_size] tensor containing the log-likelihood of each example. given the 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.
tf.contrib.crf.viterbi_decode(score=, transition_params=)

返回得分最高的标签序列。只能用在训练集中。在 tensorflow 外部解码。

参数

  • socre:形如 [seq_len, num_tags] 的矩阵,表示单点势能 unary potentials
  • transition_params:形如 [num_tags, num_tags] 的矩阵,表示 binary potentials

返回

  • viterbi:大小为 seq_len 的整数列表,表示得分最高的标签索引。
  • viterbi_score:浮点数,表示 Viterbi 序列的得分。
tf.contrib.crf.crf_decode(potentials=, transition_params=, sequence_length=)

Decode the highest scoring sequence of tags in TensorFlow.
This is a function for tensor.

参数

  • potentials:形如 [batch_size, max_seq_len, num_tags] 的张量,表示单点势能。
  • transition_params:形如 [num_tags, num_tags] 的矩阵,表示 binary potentials
  • sequence_length:大小为 batch_size 的向量,表示序列长度。

返回

  • decode_tags:形如 [batch_size, max_seq_len] 的矩阵,类型是 tf.float32,表示得分最高的标签索引。
  • best_score:大小为 batch_size 的向量,表示 decode_tags 的得分。

暂时仅了解这些代码的使用,后面有空再详细了解马尔科夫随机场,具体相关的内容可以移步参考马尔科夫随机场

Q&A

  1. binary potentials 是什么?unary potentials 呢?
  2. 待续,
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 编程规范推荐 1.命名风格推荐 1.1 如果使用到了设计模式,建议在类名中体现出具体模式。 说明: 将设计模式...
    QQqyy阅读 369评论 0 0
  • 我想,我的同龄人都觉得学习很讨厌,都想做自己喜欢的事情,而不是学习。尽管我也不太喜欢学习,但是总听妈妈说“一分...
    慕馨阅读 162评论 0 1
  • 晨绿入我心, 我心似碧波, 碧波闪光辉, 光辉映江景。
    明月映我心阅读 456评论 2 28
  • 小丫头最近老是跟我抱怨牙痛,我叫她张开嘴巴,找根筷子轻轻地敲了敲她说的疼痛处,下排两颗小巧的门牙已经稍微松动。十几...
    移云藏月阅读 933评论 16 15