Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-294

Repetition Penalty on Sequence Score

Problem

Score a generated token sequence with a repetition penalty. tokens and logprobs are parallel lists, and penalty is the multiplicative penalty applied to any token that already appeared earlier in the sequence.

For a repeated token, replace its log probability lp with lp - log(penalty); first occurrences are unchanged. Return the total penalized log probability. penalty is assumed positive.

Hint

Subtracting log(penalty) is the same as dividing the probability by penalty.

Test cases

case 1
in: [["a","b","a"],[-0.5,-0.4,-0.3],2]
expected: -1.8931471805599451
case 2
in: [["a","b","c"],[-0.5,-0.4,-0.3],2]
expected: -1.2
case 3
in: [["a","a","a"],[-1,-1,-1],1]
expected: -3
case 4
in: [[],[],2]
expected: 0
case 5
in: [["x","x","x"],[-1,-1,-1],10]
expected: -7.605170185988092
Starter codePython
import math
def repetition_penalty_sequence_score(tokens, logprobs, penalty):
    # Your code here
    pass

5 test cases · run your code against them in the editor