All problems
Length Penalty Reward
Problem
Apply a length penalty to rewards: r_i - alpha * length_i for each pair of reward and length.
The signature is length_penalty_reward(rewards, lengths, alpha).
Hint
Penalizing length discourages padding and rambling generations.
Test cases
case 1
in: [[1,2],[10,20],0.01]
expected: [0.9,1.8]
case 2
in: [[0],[5],0.1]
expected: [-0.5]
case 3
in: [[2,3],[0,4],0.5]
expected: [2,1]
case 4
in: [[1],[3],0]
expected: [1]
Starter codePython
def length_penalty_reward(rewards, lengths, alpha):
# Your code here
pass4 test cases · run your code against them in the editor