Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-080

Repetition Penalty for Generated Tokens

Problem

Apply the repetition penalty to a list of logits. For every index in previous, divide a positive logit by penalty or multiply a non-positive logit by penalty, leaving other logits unchanged.

Later duplicates of an index apply the penalty again.

Hint

Positive logits are divided and negative logits are multiplied so both move down.

Test cases

case 1
in: [[1,-1,2],[0,2],2]
expected: [0.5,-1,1]
case 2
in: [[2,-2,0],[0,1],1]
expected: [2,-2,0]
case 3
in: [[4,4],[0,1],2]
expected: [2,2]
case 4
in: [[0.5,-0.5],[0,1],2]
expected: [0.25,-1]
case 5
in: [[1],[],2]
expected: [1]
Starter codePython
def repetition_penalty(logits, previous, penalty):
    # Your code here
    pass

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