DataCollator pads to max_length and sets attention_mask = ones: find what breaks
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Click any words you think contain an error. Click again to unmark.
Two coupled bugs. The all-ones attention mask makes the model attend to pad tokens; labels equal to input_ids makes cross-entropy grade the model on predicting pad given pad.
Picture a classroom where the teacher hands every student a worksheet with 20 problems, but most students only need to solve 5. The other 15 slots are filled with blank placeholder rows so all worksheets look the same size. Now imagine the teacher grades every row including the placeholders, and treats blank placeholders as if they were real problems the student answered correctly. Two things go wrong. Students who copy a lot of placeholders get suspiciously high scores. And during class discussion, students start studying the placeholders as if they were real content. That is exactly what this collator does: it grades the model on predicting blank padding, and it lets the model spend its attention budget studying those blanks instead of the real question.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: attention mask role + softmax contamination from all-ones + labels equal to input_ids puts loss on pad + dilution math + correct collator construction + diagnostic signals.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Fixing only the attention mask and leaving labels equal to input_ids. The loss masking bug is independent and still dominates the gradient signal once the attention bug is gone.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.