NousResearch/datatrove
forked from huggingface/datatrove
Captured source
source ↗NousResearch/datatrove
Description: Freeing data processing from scripting madness by providing a set of platform-agnostic customizable pipeline processing blocks.
License: Apache-2.0
Stars: 8
Forks: 2
Open issues: 0
Created: 2025-01-13T20:59:53Z
Pushed: 2025-01-13T21:07:42Z
Default branch: main
Fork: yes
Parent repository: huggingface/datatrove
Archived: no
README:
DataTrove
DataTrove is a library to process, filter and deduplicate text data at a very large scale. It provides a set of prebuilt commonly used processing blocks with a framework to easily add custom functionality.
DataTrove processing pipelines are platform-agnostic, running out of the box locally or on a slurm cluster. Its (relatively) low memory usage and multiple step design makes it ideal for large workloads, such as to process an LLM's training data.
Local, remote and other file systems are supported through fsspec.
Table of contents
- [Installation](#installation)
- [Quickstart examples](#quickstart-examples)
- [Terminology](#terminology)
- [Pipeline](#pipeline)
- [DataTrove Document](#datatrove-document)
- [Types of pipeline blocks](#types-of-pipeline-blocks)
- [Full pipeline](#full-pipeline)
- [Executors](#executors)
- [LocalPipelineExecutor](#localpipelineexecutor)
- [SlurmPipelineExecutor](#slurmpipelineexecutor)
- [Logging](#logging)
- [DataFolder / paths](#datafolder--paths)
- [Practical guides](#practical-guides)
- [Reading data](#reading-data)
- [Extracting text](#extracting-text)
- [Filtering data](#filtering-data)
- [Saving data](#saving-data)
- [Deduplicating data](#deduplicating-data)
- [Summary Statistics](#summary-statistics)
- [Custom blocks](#custom-blocks)
+ [Simple data](#simple-data) + [Custom function](#custom-function) + [Custom block](#custom-block)
- [Contributing](#contributing)
- [Citation](#citation)
Installation
pip install datatrove[FLAVOUR]
Available flavours (combine them with , i.e. [processing,s3]):
allinstalls everything:pip install datatrove[all]iodependencies to readwarc/arc/wetfiles and arrow/parquet formats:pip install datatrove[io]processingdependencies for text extraction, filtering and tokenization:pip install datatrove[processing]s3s3 support:pip install datatrove[s3]clifor command line tools:pip install datatrove[cli]
Quickstart examples
You can check the following [examples](examples):
- [fineweb.py](examples/fineweb.py) full reproduction of the FineWeb dataset
- [process_common_crawl_dump.py](examples/process_common_crawl_dump.py) full pipeline to read commoncrawl warc files, extract their text content, filters and save the resulting data to s3. Runs on slurm
- [tokenize_c4.py](examples/tokenize_c4.py) reads data directly from huggingface's hub to tokenize the english portion of the C4 dataset using the
gpt2tokenizer - [minhash_deduplication.py](examples/minhash_deduplication.py) full pipeline to run minhash deduplication of text data
- [sentence_deduplication.py](examples/sentence_deduplication.py) example to run sentence level exact deduplication
- [exact_substrings.py](examples/exact_substrings.py) example to run ExactSubstr (requires this repo)
Terminology
pipeline: a list of processing steps to execute (read data, filter, write to disk, etc)executor: runs a specific pipeline on a given execution environment (slurm, multi cpu machine, etc)job: the execution of a pipeline on a given executortask: ajobis comprised of multipletasks, and these are used to parallelize execution, usually by having eachtaskprocess ashardof data. Datatrove keeps track of which tasks have completed and when you relaunch only incomplete tasks will run.file: an individual input file (.json, .csv, etc).
> [!TIP] > Note that each file will be processed by a single task. Datatrove does not automatically split a file into multiple parts, so to fully parallelize you should have multiple medium sized files rather than a single large file)
shard: a group of input data (usually a group offiles), which will be assigned to a specifictask. Eachtaskwill process a different non overlappingshardof data, from the full list of input filesworker: compute resource that will execute a single task at a time, e.g., if you have 50 cpu cores you can run a LocalPipelineExecutor withworkers=50, to execute 50taskssimultaneously (one per cpu). Once aworkeris done with atask, it will start processing another waitingtask
> [!TIP] > Your number of tasks controls how much you can parallelize and also how much time each individual processing unit will take. If you have a small number of tasks (and they each therefore have to process a large number of files) and they fail, you will have to restart from scratch, whereas if you have a larger number of small tasks each failed task will take way less time to rerun.
> [!CAUTION] > If your tasks > files, some tasks will not process any data, so there usually isn't a point in setting tasks to a number larger than `files.
Example
Running a job to process 10000 files, on a machine with 100 cpu cores (workers). If we choose to use 1000 tasks, each one will process a shard of 10 files. workers=100 means that we can process 100 tasks at a time.
Pipeline
DataTrove Document
Each pipeline block processes data in the datatrove [Document](src/datatrove/data.py) format:
textthe actual text content for each sampleida unique id (string) for this samplemetadataa dictionary where any additional info may be stored
Types of pipeline blocks
Each pipeline block takes a generator of Document as input and returns another generator of Document.
- [readers](src/datatrove/pipeline/readers) read data from different formats and yield
Document - [writers](src/datatrove/pipeline/writers) save
Documentto disk/cloud in different formats - [extractors](src/datatrove/pipeline/extractors) extract text content from raw formats (such as webpage html)
- [filters](src/datatrove/pipeline/filters) filter out (remove) some
Documents based on specific rules/criteria - [stats](src/datatrove/pipeline/stats) blocks to collect statistics on the dataset
-…
Excerpt shown — open the source for the full document.
Notability
notability 1.0/10Routine fork, low stars