-
Notifications
You must be signed in to change notification settings - Fork 510
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
Added generate.probabilities
for BeamSearch
#895
base: main
Are you sure you want to change the base?
Conversation
generate.probabilities
for `BeamSearch
0ac63f1
to
3493539
Compare
f6cedd6
to
4f0766b
Compare
generate.probabilities
for `BeamSearchgenerate.probabilities
for BeamSearch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great contribution!
We'll likely be moving models.transformers
to SequenceGeneratorAdapter
in #966 once there is a new transformers release (along with models.llamacpp
, models.mamba
, and models.vllm
).
IMO we should hold off on this PR until we've moved transformers to SequenceGeneratorAdapter
so we can ensure the changes continue to work.
model = models.transformers("mistralai/Mistral-7B-v0.1") | ||
probabilities = generate.probabilities(model, ["skirt", "dress", "pen", "jacket"]) | ||
answer = probabilities("Pick the odd word out: skirt, dress, pen, jacket") | ||
print(answer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please see the answer printed?
assert isinstance( | ||
sampler, BeamSearchSampler | ||
), "Only BeamSearchSampler is supported for probabilities" | ||
generator = regex(model, regex_str, sampler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns a SequenceGeneratorAdapter
in some cases.
This uses the
sequence_weights
returned by theBeamSearch
sampler to augment the results with associated probabilities, as discussed in #479.