【深度学习】tf.contrib.crf.crf_log_likelihood()在使用crf做序列标注的损失函数

写之前写吐槽一下,当时写代码的时候看了一下CRF的推导怎么都看不懂,所以当时写的时候从别人的代码直接复制出来,今天面试的时候被面试官问了,结束后研究一下,发现代码真的好简单、、。。。。。。

tf.contrib.crf.crf_log_likelihood()

代码实现细节在这里,,,我只是为了看一下[transition_params],其实他也事一个variable,所以可以存储保存下来(https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/contrib/crf/python/ops/crf.py)
最大似然估计损失函数

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

Defined in tensorflow/contrib/crf/python/ops/crf.py.

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

Args:
inputs: 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.

输入

inputs: 一个形状为[batch_size, max_seq_len, num_tags] 的tensor,一般使用BILSTM+加一个全连接映射层,映射成和我们和我们标签个数同宽的,处理之后输出转换为他要求的形状作为CRF层的输入.
tag_indices: 一个形状为[batch_size, max_seq_len] 的矩阵…真实标签.
sequence_lengths: 一个形状为 [batch_size] 的向量,表示每个序列的长度.
transition_params: 形状为[num_tags, num_tags] 的转移矩阵 (注意:这由调用者提供或在此函数中创建,一般都是让函数自己创建)

返回:

log_likelihood: 标量,log-likelihood
transition_params: 形状为[num_tags, num_tags] 的转移矩阵

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值