-
Notifications
You must be signed in to change notification settings - Fork 140
Feature/test time scaling and audio support #243
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
Open
Rakshitha-Ireddi
wants to merge
10
commits into
lotus-data:main
Choose a base branch
from
Rakshitha-Ireddi:feature/test-time-scaling-and-audio-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
26e7d1a
feat(ensembling): add test-time scaling strategies for semantic opera…
471afcd
feat(audio): add AudioArray extension for audio data support
3df7d59
test: add comprehensive tests for ensembling and AudioArray
1877d7f
style: fix linting issues found by ruff
a09d037
feat(sem_filter): integrate audio support and ensembling params
0fc10c0
Added audio data support and test-time scaling features
Rakshitha-Ireddi 74a5300
Enhance PR description with type and checklist sections
Rakshitha-Ireddi dcf9a4f
refactor(ensembling): address PR feedback and add tests/examples
ffb1fe7
Address PR feedback: add per-run columns for ensembling, remove PR_DE…
4a23937
Enable gpt-4o-audio-preview model and use valid WAV file for audio test
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,98 @@ | ||
| """ | ||
| Example: Using Test-Time Scaling (Ensembling) with sem_filter | ||
|
|
||
| This example demonstrates how to use the new ensembling feature in sem_filter | ||
| to improve prediction accuracy by aggregating multiple LLM samples. | ||
| """ | ||
|
|
||
| import pandas as pd | ||
|
|
||
| import lotus | ||
| from lotus.models import LM | ||
| from lotus.sem_ops.ensembling import Ensemble, EnsembleConfig, EnsembleStrategy | ||
|
|
||
| # Configure the language model | ||
| lm = LM(model="gpt-4o-mini") | ||
| lotus.settings.configure(lm=lm) | ||
|
|
||
| # Create a sample DataFrame with movie reviews | ||
| df = pd.DataFrame({ | ||
| "review": [ | ||
| "This movie was absolutely fantastic! Best film I've seen all year.", | ||
| "Terrible waste of time. The plot made no sense whatsoever.", | ||
| "It was okay, had some good moments but also some boring parts.", | ||
| "A masterpiece of modern cinema. Highly recommend!", | ||
| "I fell asleep halfway through. Very disappointing.", | ||
| ] | ||
| }) | ||
|
|
||
| # Example 1: Basic ensembling with default MAJORITY_VOTE strategy | ||
| print("Example 1: Basic Ensembling (Majority Vote)") | ||
| print("-" * 50) | ||
|
|
||
| result = df.sem_filter( | ||
| "The {review} expresses a positive sentiment", | ||
| n_sample=3, # Run 3 samples and aggregate | ||
| ) | ||
|
|
||
| print(f"Filtered to {len(result)} positive reviews") | ||
| print(result) | ||
|
|
||
| # Example 2: Using a custom ensemble configuration | ||
| print("\nExample 2: Custom Ensemble Configuration (Weighted Average)") | ||
| print("-" * 50) | ||
|
|
||
| # Create a custom ensemble with weighted average strategy | ||
| config = EnsembleConfig( | ||
| strategy=EnsembleStrategy.WEIGHTED_AVERAGE, | ||
| weights=[0.5, 0.3, 0.2], # Weight earlier samples more heavily | ||
| ) | ||
| ensemble = Ensemble(config) | ||
|
|
||
| result = df.sem_filter( | ||
| "The {review} mentions specific plot details", | ||
| n_sample=3, | ||
| ensemble=ensemble, | ||
| ) | ||
|
|
||
| print(f"Filtered to {len(result)} reviews with plot details") | ||
| print(result) | ||
|
|
||
| # Example 3: Accessing per-run data | ||
| print("\nExample 3: Accessing Per-Run Data") | ||
| print("-" * 50) | ||
|
|
||
| # Use return_all=True to get full output object with per-run details | ||
| result_with_details, stats = df.sem_filter( | ||
| "The {review} is written in a sarcastic tone", | ||
| n_sample=5, | ||
| return_stats=True, | ||
| return_all=True, # Return all rows, not just filtered ones | ||
| ) | ||
|
|
||
| # The output contains predictions from all runs | ||
| # Access via the _raw_outputs attribute | ||
| print("Total samples run: 5") | ||
| print(f"Stats: {stats}") | ||
| print(result_with_details) | ||
|
|
||
| # Example 4: Consensus strategy (only returns True if all samples agree) | ||
| print("\nExample 4: Consensus Strategy") | ||
| print("-" * 50) | ||
|
|
||
| config = EnsembleConfig( | ||
| strategy=EnsembleStrategy.CONSENSUS, | ||
| default=False, # Default to False if no consensus | ||
| ) | ||
| ensemble = Ensemble(config) | ||
|
|
||
| result = df.sem_filter( | ||
| "The {review} contains extremely strong language", | ||
| n_sample=3, | ||
| ensemble=ensemble, | ||
| ) | ||
|
|
||
| print(f"Filtered to {len(result)} reviews (required unanimous agreement)") | ||
| print(result) | ||
|
|
||
| print("\nDone!") |
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 |
|---|---|---|
| @@ -1,21 +1,27 @@ | ||
| from lotus.dtype_extensions.image import ImageDtype, ImageArray | ||
| from lotus.dtype_extensions.audio import AudioDtype, AudioArray | ||
| import pandas as pd | ||
|
|
||
| pd.api.extensions.register_extension_dtype(ImageDtype) | ||
| pd.api.extensions.register_extension_dtype(AudioDtype) | ||
|
|
||
|
|
||
| def convert_to_base_data(data: pd.Series | list) -> list: | ||
| """ | ||
| Converts data to proper base data type. | ||
| - For original pandas data types, this is returns tolist(). | ||
| - For ImageDtype, this returns list of PIL.Image.Image. | ||
| - For AudioDtype, this returns list of audio data. | ||
| """ | ||
| if isinstance(data, pd.Series): | ||
| if isinstance(data.dtype, ImageDtype): | ||
| return [data.array.get_image(i) for i in range(len(data))] | ||
| if isinstance(data.dtype, AudioDtype): | ||
| return [data.array.get_audio(i) for i in range(len(data))] | ||
| return data.tolist() | ||
|
|
||
| return data | ||
|
|
||
|
|
||
| __all__ = ["ImageDtype", "ImageArray", "convert_to_base_data"] | ||
| __all__ = ["ImageDtype", "ImageArray", "AudioDtype", "AudioArray", "convert_to_base_data"] | ||
|
|
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.
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.
need to enable gpt-4o-audio-preview
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.
Done. I enabled
gpt-4o-audio-previewinmultimodality_tests.pyand updated the test to use a valid WAV file input. The testtest_filter_operation_audionow passes locally!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.
@harshitgupta412 , Could you please review the changes ?