-
Notifications
You must be signed in to change notification settings - Fork 53
feat: majority voting sampling strategy #142
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
Merged
jakelorocco
merged 16 commits into
generative-computing:main
from
yelkurdi:majority_voting
Oct 3, 2025
+447
−2
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1cfb516
initial commit for majority voting
a7f3a7d
adds .gitignore to test dir
19e36e5
removed naive exact-match and replaced it with Math-Verify
dbdb518
adjusted string comparison ref vs pred relation - fixed some type che…
18c609d
adds MBRD rougeL similarity - refactors MBRD base class
cff6f7b
Merge branch 'main' into majority_voting
yelkurdi 2577546
fixes tests removes dependency on vLLM and uses default ollama
0b6c4b0
merge main with async sampling calls, majority voting now fully suppo…
yelkurdi 5840447
minor fix to pyproject.toml
yelkurdi 35de685
allow self-voting, and default symmetry, removed redundant variables …
yelkurdi 17f05f4
Merge branch 'main' into majority_voting
yelkurdi 7829865
Merge branch 'main' into majority_voting
yelkurdi 7709b12
Added special ficture for tests to run on github action runners
yelkurdi 11f3cc5
Merge branch 'main' into majority_voting
yelkurdi 59a9398
fix: minor tweaks to get automation to pass, remove redundant mellea …
jakelorocco 2f4ed52
Merge branch 'main' into majority_voting
jakelorocco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import mellea | ||
| from mellea import MelleaSession | ||
| from mellea.backends.model_ids import OPENAI_GPT_OSS_20B, META_LLAMA_3_2_1B, IBM_GRANITE_4_TINY_PREVIEW_7B | ||
| from mellea.stdlib.base import CBlock, SimpleContext | ||
| from mellea.stdlib.requirement import check, req, simple_validate | ||
| from mellea.stdlib.sampling import MBRDRougeLStrategy, MajorityVotingStrategyForMath | ||
| from mellea.backends.openai import OpenAIBackend | ||
| from mellea.backends.formatter import TemplateFormatter | ||
| from transformers import AutoTokenizer | ||
| import pytest | ||
| import os | ||
|
|
||
|
|
||
| class TestMajorityVoting: | ||
| m = mellea.start_session(ctx=SimpleContext()) | ||
|
|
||
| def test_majority_voting_for_math(self): | ||
|
|
||
| query = "Compute 1+1" | ||
| prompt_suffix = "\nPlease reason step by step, use \n\n to end each step, and put your final answer within \\boxed{}." | ||
| prompt = query + prompt_suffix | ||
|
|
||
| result = self.m.instruct( | ||
| prompt, | ||
| # requirements=requirements, | ||
| strategy=MajorityVotingStrategyForMath(number_of_samples=8, loop_budget=1), | ||
| # user_variables={"name": name, "notes": notes}, | ||
| return_sampling_results=True, | ||
| ) | ||
| if result.success: | ||
| output = str(result.result) | ||
| else: | ||
| output = result.sample_generations[0].value | ||
|
|
||
| print(output) | ||
| assert output | ||
|
|
||
|
|
||
| def test_MBRDRougeL(self): | ||
|
|
||
| requirements = [ | ||
| req("The email should have a salutation"), # == r1 | ||
| req( | ||
| "Use only lower-case letters", | ||
| validation_fn=simple_validate(lambda x: x.lower() == x), | ||
| ), # == r2 | ||
| check("Do not mention purple elephants."), # == r3 | ||
| ] | ||
|
|
||
| name = "Olivia" | ||
| notes = "Olivia helped the lab over the last few weeks by organizing intern events, advertising the speaker series, and handling issues with snack delivery." | ||
| email_candidate = self.m.instruct( | ||
| "Write an email to {{name}} using the notes following: {{notes}}.", | ||
| requirements=requirements, | ||
| strategy=MBRDRougeLStrategy(number_of_samples=8, loop_budget=1), | ||
| user_variables={"name": name, "notes": notes}, | ||
| return_sampling_results=True, | ||
| ) | ||
|
|
||
| if email_candidate.success: | ||
| output = str(email_candidate.result) | ||
| else: | ||
| output = email_candidate.sample_generations[0].value | ||
|
|
||
| print(output) | ||
| assert output | ||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main(["-s", __file__]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.