# AI use cases for Datatrove (huggingface/datatrove)

Repo: [huggingface/datatrove](https://github.com/huggingface/datatrove) | Use cases: 3 | Page: https://dedupedai.com/use-cases/huggingface-datatrove/

DataTrove is a library to process, filter and deduplicate text data at a very large scale. It provides prebuilt blocks for reading, extracting, filtering, deduplicating and tokenizing, and the same pipeline runs locally or on a slurm cluster.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Sample a text dataset with a DataTrove pipeline: https://dedupedai.com/use-cases/huggingface-datatrove/sample-and-rewrite-a-text-dataset-with-datatrove/
- Run a pipeline in parallel on one machine: https://dedupedai.com/use-cases/huggingface-datatrove/run-a-datatrove-pipeline-in-parallel-locally/
- Install the extras for a full corpus pipeline: https://dedupedai.com/use-cases/huggingface-datatrove/install-datatrove-extras-for-a-full-corpus-pipeline/

## How to sample a text dataset with a DataTrove pipeline with Datatrove

Repo: [huggingface/datatrove](https://github.com/huggingface/datatrove) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Read a CSV, randomly drop half the documents and write JSONL.

**Who it is for:** An engineer building a smaller training subset from a large corpus.

**The problem:** Hand written scripts for reading, filtering and writing documents do not scale or compose.

**The outcome:** A folder of JSONL files holding roughly half of your documents.

### Steps

1. Install with `uv sync`
2. Import `from datatrove.pipeline.readers import CSVReader`
3. Add `SamplerFilter(rate=0.5)` between the reader and `JsonlWriter`
4. Point `data_folder` and `output_folder` at your own paths
5. Run the pipeline with an executor

### Prompt to paste into your agent

```text
Using huggingface/datatrove, run `uv sync`, then build a pipeline with `CSVReader`, `SamplerFilter(rate=0.5)` and `JsonlWriter` for my data folder and run it.
```

### Caveat

This card is written from the huggingface/datatrove README, not from a test run by Deduped. Before you start, make sure you have Python 3.11 or newer. Check the repo for newer instructions before you rely on these steps.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/huggingface-datatrove/sample-and-rewrite-a-text-dataset-with-datatrove/

## How to run a pipeline in parallel on one machine with Datatrove

Repo: [huggingface/datatrove](https://github.com/huggingface/datatrove) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Use LocalPipelineExecutor with several workers and resume failed tasks.

**Who it is for:** An engineer processing a big corpus on a single workstation.

**The problem:** A single process is too slow, and rerunning everything after one failure wastes hours.

**The outcome:** A completed run with logs, plus the ability to relaunch only failed tasks.

### Steps

1. Install with `uv sync`
2. Import `from datatrove.executor import LocalPipelineExecutor`
3. Create the executor with `tasks=10` and `workers=5`, plus a `logging_dir` of your own
4. Call `executor.run()`
5. If tasks fail, relaunch the exact same executor without changing the task count

### Prompt to paste into your agent

```text
With huggingface/datatrove, wrap my pipeline in `LocalPipelineExecutor` using `tasks=10` and `workers=5`, then call `executor.run()` and report failures.
```

### Caveat

The README warns not to change the total number of tasks when relaunching.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/huggingface-datatrove/run-a-datatrove-pipeline-in-parallel-locally/

## How to install the extras for a full corpus pipeline with Datatrove

Repo: [huggingface/datatrove](https://github.com/huggingface/datatrove) | Difficulty: Advanced | Time: 1 hour | Basis: From the README

Pick the dependency flavours you need and start from the minhash deduplication example.

**Who it is for:** An engineer who wants to reproduce a deduplication pipeline.

**The problem:** It is unclear which optional dependencies each pipeline block needs.

**The outcome:** An environment with every block installed, ready for the example pipelines.

### Steps

1. Clone the repo and run `uv sync --extra all`
2. Or combine flavours such as `uv sync --extra processing --extra s3`
3. Open `examples/minhash_deduplication.py`
4. Adapt the input and output paths to your data and run it

### Prompt to paste into your agent

```text
In huggingface/datatrove run `uv sync --extra all`, read examples/minhash_deduplication.py and adapt it to deduplicate my text data.
```

### Caveat

This card is written from the huggingface/datatrove README, not from a test run by Deduped. Before you start, make sure you have Python 3.11 or newer. Check the repo for newer instructions before you rely on these steps.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/huggingface-datatrove/install-datatrove-extras-for-a-full-corpus-pipeline/
