-
Notifications
You must be signed in to change notification settings - Fork 73
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
How do I start enforcing schema only after a keyword is hit during inference? #120
Comments
Interesting. It should be possible to chain several parsers, for example something like (this is pseudocode for the LM Format Enforcer)
RegexParser, SequenceParser and JsonSchemaParser are all existing classes.
As in this way, it is mandatory to start the json output at a specific point, where it makes sense conversation wise. In the first scenario, the LLM might want to end the response, and LMFE won't let it (because it didn't output json yet), causing hallucinations. |
With regards to the first scenario, what if you did something like this:
I think I would have to modify Sequence parser can_end so it could stop on any, instead of all here:
But then now the LLM can end the conversation if it encounters an EOS or stopword before JSON is emitted if the conversation is appropriate, avoiding nasty hallucinations. I would like to open a PR by adding a new parser that does effectively this with one-shot. Is this the right direction or am I overcomplicating things? |
I'm not sure it warrants a PR, its OK if your code has classes from the LMFE hierarchy. Maybe it could be a sample. |
For example, sometimes during chain of reasoning, it is helpful to have the model reason about the answer in free-form, then output the JSON. So perhaps inference could start without enforcement, then when “‘’’\n{“ is encountered, then start enforcement.
The text was updated successfully, but these errors were encountered: