feat: add SimilarityFilterBlock for near-duplicate filtering#723
Closed
UgaTheDev wants to merge 1 commit intoinstructlab:mainfrom
Closed
feat: add SimilarityFilterBlock for near-duplicate filtering#723UgaTheDev wants to merge 1 commit intoinstructlab:mainfrom
UgaTheDev wants to merge 1 commit intoinstructlab:mainfrom
Conversation
Add a new SimilarityFilterBlock that removes near-duplicate rows from a Dataset based on text similarity using difflib.SequenceMatcher. Supports configurable similarity threshold and optional group_by column to scope deduplication within groups. Zero new dependencies.
Open
3 tasks
Author
|
Closing — this was submitted to the wrong repository. The SimilarityFilterBlock belongs in Red-Hat-AI-Innovation-Team/sdg_hub, not instructlab/sdg. Will resubmit there. |
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
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.
Summary
Adds a standalone
SimilarityFilterBlocktoinstructlab-sdgthat removes near-duplicate rows from a HuggingFaceDatasetbased on text similarity.This is a follow-up to Red-Hat-AI-Innovation-Team/sdg_hub#652, where this block was originally part of a larger InstructLab Q&A pipeline PR. Per the maintainer feedback, the
SimilarityFilterBlockwas identified as a genuinely useful, framework-agnostic addition that benefits all users and was welcomed as a separate PR.Design
The block follows the existing
FilterByValueBlockpattern exactly:Block(ABC base class)@BlockRegistry.register("SimilarityFilterBlock")_similarity,_deduplicate_group) to avoid pickling issues with multiprocessinginstructlab.sdgpublic APIParameters
filter_columnstrthresholdfloat0.85group_bystr | NoneNoneAlgorithm
Datasetto pandas DataFramegroup_byis set and column exists, group by that columndifflib.SequenceMatcher.ratio()Datasetviadataset_from_pandas_dataframeDependencies
Zero new dependencies. Uses only
difflib.SequenceMatcher(stdlib) andpandas/datasets(already required).Files Changed
src/instructlab/sdg/blocks/similarityfilterblock.pysrc/instructlab/sdg/__init__.py__all__and importstests/unit/test_similarityfilterblock.pyUsage Example
In pipeline YAML:
Test Plan
group_byisolates groups correctlygroup_bydeduplicates within same grouptesserocr/submodlib-py)from instructlab.sdg import SimilarityFilterBlock