-
Notifications
You must be signed in to change notification settings - Fork 26.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Positive Constraint Decoding PR #1 #15299
Closed
Closed
Conversation
This file contains 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
… leading to undersirable outputs
The documentation is not available anymore as the PR was closed or merged. |
cwkeam
changed the title
Positive Constraint Decoding PR #1
[WIP] Positive Constraint Decoding PR #1
Jan 29, 2022
@patrickvonplaten Sorry for the confusion but I've closed this one and opened a new PR from a new branch with a lot more updates here #15416. Safe to leave this closed. |
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.
Disjunctive Positive Constraint Decoding
@patrickvonplaten @LysandreJik @sgugger @patil-suraj @yjernite @thomwolf
Fixes #14081.
I apologize if this isn't a proper way to deal with feature contributions, but this is an incomplete PR request. I simply thought this was a good place to check-in and checkpoint on the progress & direction of the implementation. We can just work by keep adding commits to this PR request and progress until it's ready for final merge right?
Steps left:
Here is an example of how one could use this functionality:
For some example outputs:
1. General Constraint Framework
Users can define their own constraints by inheriting the
Constraint
interface class and this framework is ensured to work as desired, because theConstraint
class is quite strictly defined. If an implementation passes theself.test()
function of this interface then it necessarily works as desired. An incorrect implementation will lead to an error.For now, I've defined
TokenConstraint
for forcing the generation of a specific token andPhrasalContstraint
for forcing the generation of a sequence of tokens that are not broken in the output. The example use of the latter is in the example code above.2.
model.generate()
MixinLeads to:
Which ends up defining a
ConstrainedBeamSearchScorer
and initiates the beam search:3. Future Steps
1. Disjunctive Constraints
This doesn't yet do the Disjunctive decoding explained in the Issue #14081 . But this can be very easily implemented by simply defining a new
Constraint
sub-class. I will follow up with this with another commit.2. Tests
I was unsure how to approach testing this generation function, especially since it's almost identical to the existing approaches, with just another step included that guides the generation.