Curate TextLoad Data

Read Existing Data

View as Markdown

Use Curator’s JsonlReader and ParquetReader to read existing datasets into a pipeline, then optionally add processing stages.

:sync: jsonl

Example: Read JSONL and Filter

1from nemo_curator.core.client import RayClient
2from nemo_curator.pipeline import Pipeline
3from nemo_curator.stages.text.io.reader import JsonlReader
4from nemo_curator.stages.text.modules import ScoreFilter
5from nemo_curator.stages.text.filters import WordCountFilter
6
7# Initialize Ray client
8ray_client = RayClient()
9ray_client.start()
10
11# Create pipeline for processing existing JSONL files
12pipeline = Pipeline(name="jsonl_data_processing")
13
14# Read JSONL files
15reader = JsonlReader(
16 file_paths="/path/to/data",
17 files_per_partition=4,
18 fields=["text", "url"] # Only read specific columns
19)
20pipeline.add_stage(reader)
21
22# Add filtering stage
23word_filter = ScoreFilter(
24 filter_obj=WordCountFilter(min_words=50, max_words=1000),
25 text_field="text"
26)
27pipeline.add_stage(word_filter)
28
29# Add more stages to pipeline...
30
31# Execute pipeline
32results = pipeline.run()
33
34# Stop Ray client
35ray_client.stop()

Reader Configuration

Common Parameters

Both JsonlReader and ParquetReader support these configuration options:

ParameterTypeDescriptionDefault
file_pathsstr | list[str]File paths or glob patterns to readRequired
files_per_partitionint | NoneNumber of files per partition. Overrides blocksize if both are provided.None
blocksizeint | str | NoneTarget partition size (e.g., “128MB”). Ignored if files_per_partition is provided.None
fieldslist[str] | NoneColumn names to read (column selection)None (all columns)
read_kwargsdict[str, Any] | NoneExtra arguments for the underlying readerNone

Parquet-Specific Features

ParquetReader provides these optimizations:

  • PyArrow Engine: Uses pyarrow engine by default for better performance
  • Storage Options: Supports cloud storage via storage_options in read_kwargs
  • Schema Handling: Automatic schema inference and validation
  • Columnar Efficiency: Optimized for reading specific columns

Performance Tips

  • Use fields parameter to read required columns for better performance
  • Set files_per_partition based on your cluster size and memory constraints
  • Use blocksize for fine-grained control over partition sizes

Output Integration

Both readers produce DocumentBatch tasks that integrate seamlessly with:

  • Processing Stages: Apply filters, transformations, and quality checks
  • Writer Stages: Export to JSONL, Parquet, or other formats
  • Analysis Tools: Convert to Pandas/PyArrow for inspection and debugging