All problems
Presence Penalty Apply
Problem
Apply the OpenAI-style presence penalty: subtract penalty once from the logit of every token that has already been generated, no matter how many times it appeared.
The signature is presence_penalty(logits, generated_ids, penalty). Return a copy of the logits.
Hint
Presence penalizes whether a token appeared, while frequency penalizes how often.
Test cases
case 1
in: [[1,2,3],[0,0],0.5]
expected: [0.5,2,3]
case 2
in: [[0,0],[1],1]
expected: [0,-1]
case 3
in: [[1,2],[],0.5]
expected: [1,2]
case 4
in: [[1,1],[0,1],0.25]
expected: [0.75,0.75]
Starter codePython
def presence_penalty(logits, generated_ids, penalty):
# Your code here
pass4 test cases · run your code against them in the editor