fix: prevent infinite whitespace in grammar rules (fixes #93)#95
Open
awanawana wants to merge 1 commit intoMaximilian-Winter:masterfrom
Open
fix: prevent infinite whitespace in grammar rules (fixes #93)#95awanawana wants to merge 1 commit intoMaximilian-Winter:masterfrom
awanawana wants to merge 1 commit intoMaximilian-Winter:masterfrom
Conversation
Fixes Maximilian-Winter#93 The whitespace rule `ws ::= ([ \t\n]+)` allows unlimited consecutive whitespace characters. At higher temperatures (e.g., 0.8), this can cause the model to generate endless tabs/spaces, resulting in: - Token exhaustion - Invalid JSON output - ~10% failure rate in function calling Changed to `ws ::= ([ \t\n]?)` which: - Allows zero or one whitespace character - Prevents infinite loops while maintaining JSON validity - More restrictive than `{1}` (allows optional whitespace) Tested with Mistral 7B Instruct v0.2. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
@Maximilian-Winter peace and friendship! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ws ::= ([ \t\n]+)tows ::= ([ \t\n]?)to prevent token exhaustionProblem
As reported in #93, the current whitespace rule allows unlimited consecutive whitespace:
At temperature 0.8, this causes ~10% of function calls to fail with endless
\trepetition, producing invalid JSON.Solution
Changed to:
This allows zero or one whitespace character:
{1}(exactly one) for edge cases where no whitespace is neededTesting
?quantifier is slightly more flexible than{1}while still preventing the infinite loopRelated
Fixes #93
🤖 Generated with Claude Code