Skip to content

[scorer] - fix: padding tokens - #83

Merged
JulesBelveze merged 1 commit into
mainfrom
fix/padding-token
Jan 11, 2026
Merged

[scorer] - fix: padding tokens#83
JulesBelveze merged 1 commit into
mainfrom
fix/padding-token

Conversation

@JulesBelveze

@JulesBelveze JulesBelveze commented Jan 11, 2026

Copy link
Copy Markdown
Owner

Description

Improves handling of special token indices in LMScorer by introducing utility functions _get_fallback_pad_token_id() and _replace_ignore_index(). Replaces hardcoded -100 (ignore index) checks with reusable helper functions, adds fallback logic to handle tokenizers without a pad_token_id (trying eos_token_id, unk_token_id, or defaulting to 0), and improves type hints. Enhances robustness when decoding labels that contain ignore indices.

Risk

Low - refactoring existing logic into helper functions with improved fallback handling. The behavior remains the same for tokenizers with pad_token_id defined, and adds graceful fallback for edge cases.

Tests

Existing LMScorer tests cover the functionality.

…token indices

 - Implement utility function to get a fallback pad token ID when necessary, ensuring compatibility with various tokenizers
 - Refine the replacement of `IGNORE_INDEX` with appropriate token IDs across different methods to address special cases and simplify the logic
 - Replace hardcoded ignore index checks and token ID replacements with function calls to enhance code maintainability and readability
@JulesBelveze
JulesBelveze merged commit 79f2700 into main Jan 11, 2026
9 checks passed
@JulesBelveze
JulesBelveze deleted the fix/padding-token branch January 11, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant