12

I am running into this error while trying to use tf.nn.ctc_loss through keras (ctc_batch_cost):

InvalidArgumentError (see above for traceback): sequence_length(4) <= 471

According to the documentation for tf.nn.ctc_loss, Input requirements are:

sequence_length(b) <= time for all b

max(labels.indices(labels.indices[:, 1] == b, 2)) <= sequence_length(b) for all b.

I am having a hard time understanding what this means-- what is b and what is sequence_length(b)?

user740857
  • 475
  • 4
  • 11

1 Answers1

7

In this case b is each example in a minibatch. sequence_length(b) is the number of time stamps you have for that example. This is specified in the sequence_length argument passed to tf.nn.ctc_loss which is a 1-d tensor of sequence lengths.

Alexandre Passos
  • 5,186
  • 1
  • 14
  • 19
  • What does `time` mean in this case? I get it that `sequence_length(b) <= time for all b` means that the sequence length of each example in a minibatch should be less than or equal to `time`. Care to give an example? – Rocket Pingu Jan 30 '18 at 04:01
  • 2
    sequence_length should be a tensor representing the sizes of each sequence in your minibatch. time is the second dimension of your data tensor (which should be ordered as [batch, time, ...]). This just says that the sequence length of each example should be less than the maximum size of the time dimension – Alexandre Passos Jan 31 '18 at 21:11
  • So if I pass a `Tensor` with a reduced `time` dimension due to the layers it has gone through (e.g. convolution with max pooling followed by lstm) to `ctc_loss`, should the `sequence_length` be less that that `time` dimension? – Rocket Pingu Feb 01 '18 at 01:14
  • 1
    yes. The sequence length for each example should refer to what the time dimension would be if you only had that example in the minibatch – Alexandre Passos Feb 02 '18 at 23:57
  • Shouldn't the `sequence_length` for each example just be equal to the time dimension? In what cases would I want the `sequence_length` be less than the time dimension? – Rocket Pingu Feb 04 '18 at 23:05
  • 1
    What if one example has 10 time steps and another only has 5, and you still want to minibatch your computation? – Alexandre Passos Feb 05 '18 at 18:09
  • Does sequence_length(b) refer to the sequence length of the target or the sequence length of the input (being the number of timesteps)? – Rocket Pingu Feb 11 '18 at 03:48
  • 1
    Length of the input sequence. – Alexandre Passos Feb 12 '18 at 04:20
  • I'm confused. I checked this [test](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/kernel_tests/ctc_loss_op_test.py) for `ctc_loss` and the sequence lengths are attached to the targets. Is it just a coincidence that the number of time steps is equal to the length of each target? – Rocket Pingu Feb 15 '18 at 02:35