Download res/minhash_deduplication.patch from p4llms/p4dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/datasets/p4llms/p4dataset/resolve/main/res/minhash_deduplication.patch
- Command line
-
hf download hf://datasets/p4llms/p4dataset/res/minhash_deduplication.patch
-
curl -L -o minhash_deduplication.patch https://huggingface.co/datasets/p4llms/p4dataset/resolve/main/res/minhash_deduplication.patch
2.43 kB
| diff --git a/near_deduplication/minhash_deduplication.py b/near_deduplication/minhash_deduplication.py | |
| index e423541..e442eed 100644 | |
| --- a/near_deduplication/minhash_deduplication.py | |
| +++ b/near_deduplication/minhash_deduplication.py | |
| # created : 10/4/22 | |
| from __future__ import annotations | |
| +import json | |
| import gc | |
| import hashlib | |
| import logging | |
| logger.setLevel(logging.INFO) | |
| datasets.logging.set_verbosity_error() | |
| +def fix_json(injsfile, outjsfile): | |
| + with open(injsfile, "rt") as fin: | |
| + lines = fin.readlines() | |
| + | |
| + fixed_lines = [] | |
| + for line in lines: | |
| + crt = json.dumps(json.loads(line)) + "\n" | |
| + fixed_lines.append(crt) | |
| + | |
| + with open(outjsfile, "wt") as fout: | |
| + fout.writelines(fixed_lines) | |
| + | |
| + | |
| def ngrams(sequence: List[str], n: int, min_ngram_size: int) -> Iterable: | |
| """ | |
| Directly taken from nltk package to avoid dependency. | |
| if __name__ == "__main__": | |
| threshold: float = typer.Option(0.7, help="Minhash threshold"), | |
| min_ngram_size: int = typer.Option(5, help="Shorter documents will be removed"), | |
| output: str = typer.Option(None, help="Store the deduplicated dataset"), | |
| + dedupjson: str = typer.Option(None, help="Store the deduplicated dataset as json"), | |
| ): | |
| global uf | |
| OUTPUT_BASE = Path(output or "output") | |
| if __name__ == "__main__": | |
| HASH_TABLES = [defaultdict(set) for _ in range(B)] | |
| time_measures["load_dataset"] = time.time() | |
| - ds = load_dataset( | |
| - dataset, | |
| - config, | |
| - data_dir=data_dir, | |
| - split=split, | |
| - use_auth_token=True, | |
| - cache_dir=cache_dir, | |
| - revision=revision, | |
| - num_proc=os.cpu_count(), | |
| - ) | |
| + ds = load_dataset("json", data_files=dataset)["train"] | |
| time_measures["load_dataset"] = time.time() - time_measures["load_dataset"] | |
| DATA_SIZE = len(ds) | |
| PERMUTATIONS = np.array( | |
| if __name__ == "__main__": | |
| time_measures["save"] = time.time() | |
| final_data = final_data.remove_columns(["__cluster__"]) | |
| - final_data.save_to_disk(output) | |
| + final_data.to_json(output) | |
| + fix_json(output, dedupjson) | |
| time_measures["save"] = time.time() - time_measures["save"] | |
| FINAL_DATA_SIZE = len(final_data) | |