Beam Search Scoring with Length Penalty

medium
Unit 23 · Structured Output0/2 to milestone

Raw beam search favours short outputs, because every extra token adds a negative log-probability. Hugging Face's beam scorer divides the summed log-probability by a length penalty:

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Beam Search Scoring with Length Penalty · TechGradify