-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rywolf/justext
Signed-off-by: Ryan Wolf <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,683 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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,32 @@ | ||
# Configuration file for semdantic dedup | ||
cache_dir: "semdedup_cache" | ||
num_files: 16 | ||
id_col_name: "id" | ||
id_col_type: "int" | ||
input_column: "text" | ||
|
||
# Embeddings configuration | ||
embeddings_save_loc: "embeddings" | ||
embedding_model_name_or_path: "sentence-transformers/all-MiniLM-L6-v2" | ||
embedding_batch_size: 128 | ||
embedding_max_mem_gb: 25 | ||
|
||
# Clustering configuration | ||
clustering_save_loc: "clustering_results" | ||
n_clusters: 1000 | ||
seed: 1234 | ||
max_iter: 100 | ||
kmeans_with_cos_dist: false | ||
|
||
# Semdedup configuration | ||
which_to_keep: "hard" | ||
largest_cluster_size_to_process: 100000 | ||
sim_metric: "cosine" | ||
|
||
# Extract dedup configuration | ||
eps_thresholds: | ||
- 0.01 | ||
- 0.001 | ||
|
||
# Which threshold to use for extracting deduped data | ||
eps_to_extract: 0.01 |
This file contains 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 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,84 @@ | ||
# 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 logging | ||
import os | ||
import time | ||
|
||
from nemo_curator.datasets import DocumentDataset | ||
from nemo_curator.log import create_logger | ||
from nemo_curator.modules.config import SemDedupConfig | ||
from nemo_curator.modules.semantic_dedup import SemDedup | ||
from nemo_curator.utils.distributed_utils import get_client, read_data | ||
from nemo_curator.utils.file_utils import ( | ||
expand_outdir_and_mkdir, | ||
get_all_files_paths_under, | ||
) | ||
from nemo_curator.utils.script_utils import ArgumentHelper | ||
|
||
|
||
def silence_hf_warnings(): | ||
from transformers.utils import logging | ||
|
||
logging.set_verbosity_error() | ||
|
||
|
||
def main(args): | ||
semdedup_config = SemDedupConfig.from_yaml(args.config_file) | ||
client = get_client(**ArgumentHelper.parse_client_args(args)) | ||
|
||
silence_hf_warnings() | ||
client.run(silence_hf_warnings) | ||
|
||
expand_outdir_and_mkdir(semdedup_config.cache_dir) | ||
logger = create_logger( | ||
rank=0, | ||
name="logger-end-to_end-semdup", | ||
log_file=os.path.join(semdedup_config.cache_dir, "compute_embeddings.log"), | ||
log_level=logging.INFO, | ||
stdout=True, | ||
) | ||
st = time.time() | ||
input_files = get_all_files_paths_under( | ||
root=args.input_data_dir, | ||
) | ||
if semdedup_config.num_files > 0: | ||
input_files = input_files[: semdedup_config.num_files] | ||
logger.info(f"Processing {len(input_files)} files") | ||
ddf = read_data( | ||
input_files=input_files, | ||
file_type=args.input_file_type, | ||
add_filename=False, | ||
backend="cudf", | ||
) | ||
dataset = DocumentDataset(ddf) | ||
semdup = SemDedup(semdedup_config, logger=logger) | ||
dedup_ids = semdup(dataset) | ||
print(dedup_ids.df.head()) | ||
logger.info(f"Time taken: {time.time() - st}") | ||
client.cancel(client.futures, force=True) | ||
client.close() | ||
|
||
|
||
def attach_args(): | ||
parser = ArgumentHelper.parse_semdedup_args(add_input_args=True) | ||
return parser | ||
|
||
|
||
def console_script(): | ||
main(attach_args().parse_args()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(attach_args().parse_args()) |
This file contains 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 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 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
Oops, something went wrong.