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

Added generate.probabilities for BeamSearch #895

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

LouisHernandez17
Copy link

This uses the sequence_weights returned by the BeamSearch sampler to augment the results with associated probabilities, as discussed in #479.

@brandonwillard brandonwillard linked an issue May 16, 2024 that may be closed by this pull request
@brandonwillard brandonwillard changed the title [Issue #479] Added generate.probabilities for BeamSearch Added generate.probabilities for `BeamSearch May 16, 2024
@brandonwillard brandonwillard marked this pull request as draft May 16, 2024 22:00
pyproject.toml Outdated Show resolved Hide resolved
@LouisHernandez17 LouisHernandez17 marked this pull request as ready for review May 30, 2024 13:43
@rlouf rlouf changed the title Added generate.probabilities for `BeamSearch Added generate.probabilities for BeamSearch Jun 10, 2024
Copy link
Collaborator

@lapp0 lapp0 left a 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)
Copy link
Collaborator

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)
Copy link
Collaborator

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.

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

Successfully merging this pull request may close these issues.

Add probability distribution to choices
4 participants