Skip to content
ML Academy

Neural networks, deep learning, NLP · insight-1443

Choose which segment of a text pair to truncate instead of accepting the default strategy

Evidence type
documented fact
Difficulty
medium
Roles
Applied AI, ML engineer
Industries
cross-industry

Summary: situation, action, reason, boundary

  1. Situation

    A BERT-style pair classifier takes a customer message and a long policy clause with max_length=128 and truncation=True.

  2. Action

    Pick only_first or only_second for the segment that is safe to shorten, or pre-trim by sentence, and log the share of pairs truncated per segment on the dev set.

  3. Reason

    Hugging Face documents that longest_first removes tokens one at a time from the longest sequence of a pair, while only_first and only_second shorten only that segment.

  4. Boundary

    Cross-encoders, NLI-style pairs, question and context pairs.

Symptom or risk

Tokens are removed from whichever segment is longer, so the cut can fall on the exact words the label depends on, and nothing signals it.

Exceptions

If under about 1 percent of pairs are truncated the choice hardly matters.

Trade-offs

Truncating one side hard can lose more of it than a balanced cut would.

Pitfalls

Tuning max_length on the test set; comparing runs that truncated differently.

Lessons and concepts

Claims and their sources