-
Notifications
You must be signed in to change notification settings - Fork 377
Fix a tiny bug in PromptManager::FewShotSampler::_init_fewshot_sampling_random
#423
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
clefourrier
merged 7 commits into
huggingface:main
from
sadra-barikbin:Fix-tiny-bug-in-prompt-manager
Dec 12, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b3d06e1
Fix the bug and add test
sadra-barikbin 4213f1c
Fix docstring typo in prompt_manager
sadra-barikbin f6789a6
Improve test
sadra-barikbin bce77df
Merge branch 'main' into Fix-tiny-bug-in-prompt-manager
clefourrier 836ee54
Merge branch 'main' into Fix-tiny-bug-in-prompt-manager
clefourrier ca226bf
Merge branch 'main' into Fix-tiny-bug-in-prompt-manager
clefourrier 7748f32
Merge branch 'main' into Fix-tiny-bug-in-prompt-manager
clefourrier 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # MIT License | ||
|
|
||
| # Copyright (c) 2024 The HuggingFace Team | ||
|
|
||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the "Software"), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
|
|
||
| # The above copyright notice and this permission notice shall be included in all | ||
| # copies or substantial portions of the Software. | ||
|
|
||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| # SOFTWARE. | ||
|
|
||
| import random | ||
| from collections import Counter | ||
|
|
||
| import pytest | ||
|
|
||
| from lighteval.tasks.lighteval_task import LightevalTask, LightevalTaskConfig | ||
| from lighteval.tasks.prompt_manager import FewShotSampler, PromptManager | ||
| from lighteval.tasks.requests import Doc | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("fewshot_select", ["sequential", "random", "balanced"]) | ||
| def test_fewshot_sampler(fewshot_select: str): | ||
| config = LightevalTaskConfig( | ||
| name="test_fewshot_task", | ||
| prompt_function=lambda _, __: None, | ||
| hf_repo=None, | ||
| hf_subset="default", | ||
| metric=[], | ||
| few_shots_split="test", | ||
| few_shots_select=fewshot_select, | ||
| ) | ||
| task = LightevalTask("test_fewshot_task", config) | ||
| rnd = random.Random(0) | ||
| task._fewshot_docs = [ | ||
| Doc(str(i), ["A", "B"], rnd.randint(0, 2), fewshot_sorting_class=str(i % 20)) for i in range(100) | ||
| ] | ||
| sampler = FewShotSampler(task) | ||
| seed = 1 | ||
| docs = sampler.sample_fewshot_examples(20, seed) | ||
| match task.fewshot_selection: | ||
| case "balanced": | ||
| labels = Counter([PromptManager.doc_to_fewshot_sorting_class(d) for d in docs]) | ||
| assert labels.total() / len(labels) == 1 | ||
| case "sequential": | ||
| assert docs == task.fewshot_docs()[:20] | ||
| case "random": | ||
| rnd = random.Random(seed) | ||
| task_docs = task.fewshot_docs() | ||
| rnd.shuffle(task_docs) | ||
| assert docs == task_docs[:20] |
Oops, something went wrong.
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.