Repository navigation
High level fuzzy duplicates module #46
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
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0943524
Initial pass at fuzzy dedup api
ayushdg eec2cf9
Update deprecated shuffle arg
ayushdg f69c4bb
dask_cuda gpu only import
ayushdg a142798
Move fuzzy_dedup imports to optional
ayushdg 825078f
more tests
ayushdg 2f9e7af
Move FuzzyDeDupConfig to it's own class
ayushdg e54f7a9
Add example script and config file, fix typo
ayushdg 6851e41
Remove slurm examples for gpu dedup
ayushdg 11a205a
Add config module
ayushdg 572e9af
Rename FuzzyDeDupConfig and minhash_length to FuzzyDuplicatesConfig,…
ayushdg 4792b2a
Add comments and update example
ayushdg 19232ce
Write to same format as input in fuzzy dedup example
ayushdg 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| cache_dir: "./fuzzy_dedup_cache" | ||
| # Optional Params below with default values | ||
| # profile_dir: null | ||
| # id_field: "id" | ||
| # text_field: "text" | ||
|
|
||
| # seed: 42 | ||
| # char_ngrams: 5 | ||
| # num_buckets: 20 | ||
| # hashes_per_bucket: 13 | ||
| # use_64_bit_hash: false | ||
| # buckets_per_shuffle: 1 | ||
|
|
||
| # false_positive_check: True | ||
| # num_anchors: 2 | ||
| # jaccard_threshold: 0.8 |
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,109 @@ | ||
| # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import time | ||
|
|
||
| import dask | ||
| from dask import dataframe as dd | ||
|
|
||
| from nemo_curator import FuzzyDuplicates, FuzzyDuplicatesConfig | ||
| from nemo_curator.datasets import DocumentDataset | ||
| from nemo_curator.utils.distributed_utils import get_client, write_to_disk | ||
| from nemo_curator.utils.script_utils import add_distributed_args | ||
|
|
||
|
|
||
| def pre_imports(): | ||
| import cudf # noqa: F401 | ||
|
|
||
|
|
||
| def main(args): | ||
|
|
||
| dataset_dir = "/path/to/dataset" | ||
| log_dir = "./" | ||
| cache_dir = "./fuzzy_cache" | ||
| output_dir = "./output" | ||
| dataset_id_field = "id" | ||
| dataset_text_field = "text" | ||
|
|
||
| filetype = "parquet" | ||
|
|
||
| # Fuzzy dup calculation only supports the cuDF/GPU backend | ||
| backend = "cudf" | ||
| assert args.device == "gpu" | ||
|
|
||
| with dask.config.set({"dataframe.backend": backend}): | ||
| client = get_client(args, args.device) | ||
| client.run(pre_imports) | ||
|
|
||
| t0 = time.time() | ||
| if filetype == "parquet": | ||
| input_dataset = DocumentDataset( | ||
| dd.read_parquet( | ||
| dataset_dir, | ||
| columns=[dataset_id_field, dataset_text_field], | ||
| blocksize="256MiB", | ||
| aggregate_files=True, | ||
| ) | ||
| ) | ||
| elif filetype == "jsonl": | ||
| input_dataset = DocumentDataset.read_json( | ||
| dataset_dir, | ||
| backend=backend, | ||
| ) | ||
|
|
||
| fuzzy_dedup_config = FuzzyDuplicatesConfig( | ||
| cache_dir=cache_dir, | ||
| id_field=dataset_id_field, | ||
| text_field=dataset_text_field, | ||
| seed=42, | ||
| char_ngrams=5, | ||
| num_buckets=20, | ||
| hashes_per_bucket=13, | ||
| use_64_bit_hash=False, | ||
| buckets_per_shuffle=5, | ||
| false_positive_check=True, | ||
| num_anchors=2, | ||
| jaccard_threshold=0.8, | ||
| ) | ||
| fuzzy_dup = FuzzyDuplicates(logger=log_dir, config=fuzzy_dedup_config) | ||
| duplicates = fuzzy_dup(dataset=input_dataset) | ||
|
|
||
| # By default all duplicate id's and the group they belong to are included in the result | ||
| # keep 1 document from each group of duplcates and mark the others to remove | ||
| # https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.duplicated.html | ||
| docs_to_remove = duplicates.df.map_partitions( | ||
| lambda x: x[x.group.duplicated(keep="first")] | ||
| ) | ||
|
|
||
| # When there are few duplicates we can compute the results to a list and use `isin`. | ||
| result = input_dataset.df[ | ||
| ~input_dataset.df[dataset_id_field].isin( | ||
| docs_to_remove[dataset_id_field].compute() | ||
| ) | ||
| ] | ||
| write_to_disk(result, output_dir, output_type="parquet") | ||
| print(time.time() - t0) | ||
|
|
||
|
|
||
| def attach_args( | ||
| parser=argparse.ArgumentParser( | ||
| formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
| ), | ||
| ): | ||
| return add_distributed_args(parser) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main(attach_args().parse_args()) | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
examples/gpu_deduplication_example/create-list-of-exact-duplicate-ids.sh
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
examples/gpu_deduplication_example/create-list-of-fuzzy-duplicate-ids.sh
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.