1. 磐创AI-开放猫官方网站首页
  2. 机器学习
  3. TensorFlow
  4. TensorFlow函数

tf.contrib.seq2seq.sequence_loss TensorFlow seq2seq 损失函数

tf.contrib.seq2seq.sequence_loss(logits, targets, weights, average_across_timesteps=True, average_across_batch=True, softmax_loss_function=None, name=None)

Weighted cross-entropy loss for a sequence of logits (per example).

Args:

logits: A 3D Tensor of shape [batch_size x sequence_length x num_decoder_symbols] and dtype float. The logits correspond to the prediction across all classes at each timestep.
targets: A 2D Tensor of shape [batch_size x sequence_length] and dtype int. The target represents the true class at each timestep.
weights: A 2D Tensor of shape [batch_size x sequence_length] and dtype float. Weights constitutes the weighting of each prediction in the sequence. When using weights as masking set all valid timesteps to 1 and all padded timesteps to 0.
average_across_timesteps: If set, sum the cost across the sequence dimension and divide by the cost by the total label weight across timesteps.
average_across_batch: If set, sum the cost across the batch dimension and divide the returned cost by the batch size.
softmax_loss_function: Function (inputs-batch, labels-batch) -> loss-batch to be used instead of the standard softmax (the default if this is None).
name: Optional name for this operation, defaults to “sequence_loss”.
Returns:

A scalar float Tensor: The average log-perplexity per symbol (weighted).

Raises:

ValueError: logits does not have 3 dimensions or targets does not have 2 dimensions or weights does not have 2 dimensions.
Defined in tensorflow/contrib/seq2seq/python/ops/loss.py.

原创文章,作者:fendouai,如若转载,请注明出处:https://panchuang.net/2017/08/07/tf-contrib-seq2seq-sequence_loss/

发表评论

登录后才能评论

联系我们

400-800-8888

在线咨询:点击这里给我发消息

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息