-
Notifications
You must be signed in to change notification settings - Fork 27k
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
[Help] Correct Way to do Simple Model Constraints #33306
Comments
We don't support controlled LLM generation via grammar in Transformers directly, but there are many awesome external libraries for that. You might be interested in https://github.com/outlines-dev/outlines or https://github.com/uiuc-focal-lab/syncode, as an example 🤗 |
Thank you for the reply.
I'm not looking for anything this sophisticated. For the above example, I'd be just looking to set the probabilities of all tokens except 0-9 and the EOS token to 0 (which should result in it the model being forced to output an int). If the more sophisticated constrained beam search is a possibility without external libraries, then surely this simpler case is also doable without external libraries? Like I mentioned, I need to do this without external libraries. Thank you in advance. |
@JamesKCS in that case you can write your own LogitsProcessor that will set all probabilities to If you have any questions please open a discussion in the forum, we try to reserve GH for bugs and features 🤗 |
Thank you, sorry for posting this in the wrong place, I'll close this (and maybe update it later with a MWE for future searchers). |
I am trying to figure out the correct way to apply simple model output constraints with transformers. As an example, let's consider how to constrain the output to a non-negative int with an unknown number of digits (decided by the model). For example, it could output
11
, or0
, or307
, but not307.
orthe answer is 307
.I've read https://huggingface.co/blog/constrained-beam-search; this is a great resource, but it is solving a much more challenging problem than the kind of simple model constraints that I'm looking for, and it doesn't tell us how to solve this easier problem. I'm also aware of the many 3rd party packages that accomplish this, but I want to know the correct way of doing it just using the Transformers package.
Could someone point me in the right direction (perhaps there's a blog post that I missed), or give me a code snippet of the best way to accomplish this? Perhaps I should be using something from beam_constraints or tf_logits_process? Thank you.
The text was updated successfully, but these errors were encountered: