Fix group_lengths for short datasets
# What does this PR do?

This PR adds a fix in the `group_lengths` function used in all language modeling examples so it also works for short datasets (without returning a dataset of length 0). The fix was discussed in the issue mentioned below.

Fixes #12438