All problems
Batch Padding Waste Ratio
Problem
Compute the fraction of padding tokens in a padded batch: 1 - sum(lengths) / (num_sequences * max_length).
The signature is padding_waste_ratio(lengths, max_length). Return a float.
Hint
Length bucketing reduces this waste by grouping similar-length sequences.
Test cases
case 1
in: [[10,20],20]
expected: 0.25
case 2
in: [[20,20],20]
expected: 0
case 3
in: [[0],10]
expected: 1
case 4
in: [[5],10]
expected: 0.5
Starter codePython
def padding_waste_ratio(lengths, max_length):
# Your code here
pass4 test cases · run your code against them in the editor