Iterate over tokens that should be biased rather than the entire vocabulary. (#851)

This commit is contained in:
David Ponce 2023-11-01 23:53:47 +01:00 committed by GitHub
parent 9c8f4dca5f
commit 3fc9147218
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -601,10 +601,9 @@ def make_logit_bias_processor(
input_ids: npt.NDArray[np.intc],
scores: npt.NDArray[np.single],
) -> npt.NDArray[np.single]:
new_scores = [None] * len(scores)
for input_id, score in enumerate(scores):
new_scores[input_id] = score + to_bias.get(input_id, 0.0)
new_scores = np.copy(scores) # Does it make sense to copy the whole array or can we just overwrite the original one?
for input_id, score in to_bias.items():
new_scores[input_id] = score + scores[input_id]
return new_scores
return logit_bias_processor