Why are lengths relative? #2971
Replies: 1 comment
|
It is documented, but not where you were looking. There is a section titled "Why relative lengths instead of absolute lengths?" in the speech recognition from scratch tutorial, and a one-line version in the data loading tutorial:
The API reference does not say it anywhere. So your debugging session was not your fault. Where the float comes from
valid_vals.append(tensor.shape[j] / target_shape[j])
padded, valid_percent = pad_right_to(t, max_shape, mode=mode, value=value)
batched.append(padded)
valid.append(valid_percent[0])
...
return batched, torch.tensor(valid)and Where it is turned back into countsEvery consumer multiplies by the current time dimension. CTC loss, input_lens = (input_lens * log_probs.shape[1]).round().int()
target_lens = (target_lens * targets.shape[1]).round().int()Attention decoder, enc_len = torch.round(enc_states.shape[1] * wav_len).long()Note both read Why relative survives what absolute does notThe tensor is never rescaled when time resolution changes, and it does not need to be. fea_lens = wav_lens # Relative lengths are preservedRun against a current checkout: One That is the whole argument. Pooling, strided convolution, STFT hop, resampling and speed perturbation all change the number of time steps, and a pipeline that passed absolute counts would have to thread a rescale through every one of them, with each stage needing to know the previous stage's hop and padding. The relative form makes the lengths invariant to the transform, so a module only needs the tensor it was handed. The cost is the one you paid: it is a float in Docstring convention statement, for reference, |
Uh oh!
There was an error while loading. Please reload this page.
Turns out lengths across the codebase are relative.
Is this documented somewhere clearly? Took me a lot of debugging to find this out, it seems like it's an unexpected / non-standard choice.
Why was it made?
All reactions