# tf.contrib.legacy_seq2seq.sequence_loss_by_example

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py#L1052-L1100) |

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

    tf.contrib.legacy_seq2seq.sequence_loss_by_example(
        logits, targets, weights, average_across_timesteps=True,
        softmax_loss_function=None, name=None
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `logits` | List of 2D Tensors of shape \[batch_size x num_decoder_symbols\]. |
| `targets` | List of 1D batch-sized int32 Tensors of the same length as logits. |
| `weights` | List of 1D batch-sized float-Tensors of the same length as logits. |
| `average_across_timesteps` | If set, divide the returned cost by the total label weight. |
| `softmax_loss_function` | Function (labels, logits) -\> loss-batch to be used instead of the standard softmax (the default if this is None). **Note that to avoid confusion, it is required for the function to accept named arguments.** |
| `name` | Optional name for this operation, default: "sequence_loss_by_example". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| 1D batch-sized float Tensor: The log-perplexity for each sequence. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If len(logits) is different from len(targets) or len(weights). |

<br />