Based on the code, it looks like in get_caption x_len is calculated, then returned to __getitem__ as cap_len.
prepare_data gets a new sample from TextDataset (so from its __getitem__), and returns sorted_cap_lens, which is finally renamed to cap_lens.
I see your confusion and think the naming in the repo could be a bit more consistent, but maybe there is a good reason to rename the same variables.