generated from MinishLab/watertemplate
-
Notifications
You must be signed in to change notification settings - Fork 51
feat: Add entropy scoring functionality #25
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
Pringled
merged 14 commits into
MinishLab:main
from
davidberenstein1957:feat/add-scoring
Mar 25, 2025
Merged
feat: Add entropy scoring functionality #25
Pringled
merged 14 commits into
MinishLab:main
from
davidberenstein1957:feat/add-scoring
Mar 25, 2025
Conversation
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
…for deduplication - Added `score_columns` parameter to `SemHash` for scoring records based on specified columns. - Implemented `_score` method to scale and compute scores for records. - Updated `deduplicate` and `self_deduplicate` methods to incorporate scoring and budget constraints. - Refactored initialization and documentation to reflect new parameters and functionality.
- Removed unnecessary score cleanup from the records after sorting. - Moved the scoring logic to ensure records are sorted by score before deduplication. - Improved code clarity by consolidating score handling within the deduplication process.
- Renamed `_score` method to `_sort_and_scale_scores` to better reflect its functionality. - Updated references to the scoring method in the deduplication process for improved readability and accuracy.
- Added a new method `compute_nearest_neighbor_alignment_scores` to calculate embedding similarity based on nearest neighbor alignment. - Updated the SemHash initialization to optionally compute alignment scores when creating an instance. - Removed the unused `score_columns` parameter from the SemHash constructor for clarity. - Enhanced the deduplication process by integrating alignment scoring, improving overall functionality and performance.
…lt dataclass - Added a new `FilterResult` dataclass to encapsulate the results of filtering operations, including selected and filtered records along with their scores. - Implemented `filter_by_score` and `self_filter_by_score` methods in the `SemHash` class to filter records based on their scores, allowing for budget constraints and sorting options. - Updated the `Index` class to replace the deprecated `compute_nearest_neighbor_alignment_scores` method with a more streamlined `query_top_k` method for querying top-k records. - Removed unused parameters and methods to enhance code clarity and maintainability.
- Replaced `filter_by_score` with `filter_by_entropy` to compute record diversity using scipy's entropy function - Modified `query_top_k` method to handle vector queries more robustly - Added scipy>=1.13.1 as a dependency in pyproject.toml - Updated README with new entropy filtering examples and documentation - Renamed methods to use `entropy` instead of `score` for clarity - Improved filtering functionality with more intuitive parameters like `descending` and `k`
- Implemented tests for `self_filter_by_entropy` method with various scenarios - Added test cases for absolute and percentage-based budget filtering - Verified sorting order with ascending and descending entropy options - Included validation tests for invalid budget inputs - Tested string and dictionary input compatibility for entropy filtering
- Replaced `filter_by_score` with `filter_by_entropy` in README documentation - Clarified description of entropy-based filtering method - Maintained existing explanation of filtering functionality
…ation - Removed scipy>=1.13.1 from project dependencies - Created a custom `entropy_from_distances` function in utils.py to replace scipy's entropy function - Updated `semhash.py` to use the new entropy calculation method - Reshaped vector inputs to ensure compatibility with `query_top_k` method - Simplified entropy calculation with a more explicit implementation
- Updated `_validate_filter_budget` method to include a parameter for top-k records and improved budget validation logic. - Introduced `_filter_by_entropy` method to encapsulate entropy-based filtering functionality, streamlining the `filter_by_entropy` and `self_filter_by_entropy` methods. - Simplified the filtering process by leveraging the new `_filter_by_entropy` method for better code organization and readability.
|
@Pringled should be ready to go :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Inspired by approach described here: https://arxiv.org/abs/2312.15685
filter_by_scoremethod that takes records and filters them against by computing a score based on the average distance to k nearest neighbours in an index. This should probably be extended with a threshold to avoid bias for high-density regions pre-deduplication. After, it filters them based on abudget, which can be a percentage or an exact number to keep post-filtering.self_filter_by_scoremethod that does the same but within the existing index.Benchmarking. I could not find any benchmarks for this but I thought we would be able to do something with benchmarks on common tasks like text-classification and QnA pre-and post filtering with certain percentages.