title: How to calculate CTC loss of a sequence with all blanks using tf.nn.ctc_loss?
body: <p>It is straightforward to calculate CTC loss of a sequence with all blanks by hand. But, I do not find a way to do this using <a href="https://www.tensorflow.org/api_docs/python/tf/nn/ctc_loss" rel="noreferrer"><code>tf.nn.ctc_loss</code> API</a>. Do I miss something, or <code>tf.nn.ctc_loss</code> implementation lacks this feature? This feature is necessary when a few sequences in the batch have no output symbol. </p>
  
  <p><a href="https://github.com/tensorflow/tensorflow/issues/13457" rel="noreferrer">I reported this on github</a>, and it is closed with no answer. </p>
  
  <p>Environments: tf version 1.3, CPU version; python 3.5/3.6; Win10/Ubuntu 16.04.</p>
  
  <p>To begin with, we start from code:</p>
  
  <pre><code>import tensorflow as tf
  num_classes, batch_size, seq_len = 3, 1, 2
  labels = tf.SparseTensor(indices=[[0,0]], values=[0], dense_shape=[1,1])
  inputs = tf.zeros([seq_len, batch_size, num_classes])
  loss = tf.nn.ctc_loss(labels, inputs, [seq_len])
  print(tf.InteractiveSession().run(loss))
  </code></pre>
  
  <p><code>tf.nn.ctc_loss</code> behaves as expected, and print the correct answer: 1.09861231</p>
  
  <h3>Issue one:</h3>
  
  <p>How to calculate the ctc loss of a sequence with all blanks? The tf.nn.ctc_loss API requires that values &lt; num_labels, so we have no way to achieve it? If I do change the values in the above example to num_classes - 1 (the reserved blank ID), tf.nn.ctc_loss has no complain, and returns the wrong answer: 0.81093025! The correct answer is 2*log(3). The code to reproduce issue one is as below:</p>
  
  <pre><code>import tensorflow as tf
  num_classes, batch_size, seq_len = 3, 1, 2
  labels = tf.SparseTensor(indices=[[0,0]], values=[2], dense_shape=[1,1])
  inputs = tf.zeros([seq_len, batch_size, num_classes])
  loss = tf.nn.ctc_loss(labels, inputs, [seq_len])
  print(tf.InteractiveSession().run(loss))
  </code></pre>
  
  <h3>Issue two:</h3>
  
  <p>Let's change the sequence length to 1 as below</p>
  
  <pre><code>import tensorflow as tf
  num_classes, batch_size, seq_len = 3, 1, 1
  labels = tf.SparseTensor(indices=[[0,0]], values=[2], dense_shape=[1,1])
  inputs = tf.zeros([seq_len, batch_size, num_classes])
  loss = tf.nn.ctc_loss(labels, inputs, [seq_len])
  print(tf.InteractiveSession().run(loss))
  </code></pre>
  
  <p>and run the code again. This code gives the correct answer, log(3), in Ubuntu, but crashes in Win10 with message: Kernel died, restarting.</p>