Skip to content
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

Allow Tokens to Span Multiple Terminals in CFG #684

Closed
brandonwillard opened this issue Feb 20, 2024 Discussed in #683 · 2 comments · Fixed by #1067 · May be fixed by lapp0/outlines#34
Closed

Allow Tokens to Span Multiple Terminals in CFG #684

brandonwillard opened this issue Feb 20, 2024 Discussed in #683 · 2 comments · Fixed by #1067 · May be fixed by lapp0/outlines#34

Comments

@brandonwillard
Copy link
Member

Discussed in #683

Originally posted by lapp0 January 23, 2024

What behavior of the library made you think about the improvement?

Currently generated tokens must be part of a terminal, or a complete terminal. A token cannot start at one terminal and end at another.

E.g. in the gpt2 tokenizer, {" is a valid token. However if { and " are separate terminals, as in the case of a typical json grammar, { is allowed in the initial states CFGFSM.allowed_token_ids(0) but {" is not.

This approach not only deviates technically from correct grammar representation, but also adversely affects generation quality. For example in the arithmetic grammar from README.md, using mistralai/Mistral-7B-v0.2, the most probable second token is + (space-prefixed), however because space is a separate terminal this token isn't legal, it selects + instead. In scenarios like this, spaces, though grammatically valid and model-preferred, are seldom produced. This is because the model would have to select the space as a standalone token to incorporate any spaces.

How would you like it to behave?

Permit the generation of any token that complies with a grammar's production rules and is valid in the context of the preceding sequence of tokens, regardless of whether it spans multiple tokens.

This will require careful engineering and benchmarking to ensure the new trie-of-RegexFSM described at the end of section 4.2 of the outlines paper works properly.

@brandonwillard
Copy link
Member Author

Converting this back into an issue because it does mostly describe a bug-like situation with the current implementation. Design and approach proposals should take place in the discussion, though.

@rlouf rlouf moved this to Todo in Improve Outlines May 5, 2024
@lapp0
Copy link
Contributor

lapp0 commented May 31, 2024

As discussed in #796 (comment) resolving this issue will involve ensuring the parsing issues below are resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants