Fix Infinite Repetition in JSON Schemas Using Integer and String#1154
Closed
lapp0 wants to merge 1 commit intodottxt-ai:mainfrom
Closed
Fix Infinite Repetition in JSON Schemas Using Integer and String#1154lapp0 wants to merge 1 commit intodottxt-ai:mainfrom
lapp0 wants to merge 1 commit intodottxt-ai:mainfrom
Conversation
25cb1c1 to
db309ef
Compare
lapp0
commented
Sep 16, 2024
| return f'"{STRING_INNER}{{{min_length},{max_length}}}"' | ||
|
|
||
|
|
||
| def build_regex_from_schema( |
Contributor
Author
There was a problem hiding this comment.
Probably should be at the top. We might also consider separating into multiple modules so it's easier to read
Member
There was a problem hiding this comment.
Yes, I generally like to move helper functions to the end of the file.
cb970c3 to
985dc9c
Compare
Member
@cpfiffer fyi |
985dc9c to
0f1deee
Compare
…int_pattern / get_str_pattern
0f1deee to
0f7ecd4
Compare
Contributor
Author
|
We might want to hold off on this one actually. I did some profiling on The better alternative is to
Alternatively we could reduce the size of Let me know if this makes sense |
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.
Overview
The repetition problem of language models combined with patterns allowing for infinite-length fields results in broken JSON Schema outputs.
This was addressed previously for infinite whitespaces issues by setting a safe whitespace pattern as the default. In this PR, the safety of whitespaces is extended to Integer and String patterns.
Behavior
json_schema.to_regexnow includes a kwargsafe_subset=True.safe_subset=Falser"[\n\t ]*"safe_subset=True(default)r"[ ]?"Fixes
Safe Integer
Safe String
non_strictmode)Further Work
Important: In the resolved issues, the incorrect outputs are often caused by not applying a chat template. Let's help users get great completions. Examples should include chat templates, or user response quality will suffer. Format
promptsUsing Chat Templates inSequenceGeneratorAdapter#987Make code more failsafe: Add a non_strict mode to deal with JSONDecodeError errors #985
numberhas nosafe_subsetimplementation. It's likely the only unsafe primitive remaining without asafe_subsetimplementation. However, there aren't any open issues for an error caused by number.