data_juicer.format#

class data_juicer.format.JsonFormatter(dataset_path, suffixes=None, **kwargs)[source]#

Bases: LocalFormatter

The class is used to load and format json-type files.

Default suffixes is [โ€˜.jsonโ€™, โ€˜.jsonlโ€™, โ€˜.jsonl.zstโ€™]

SUFFIXES = ['.json', '.jsonl', '.jsonl.zst']#
__init__(dataset_path, suffixes=None, **kwargs)[source]#

Initialization method.

Parameters:
  • dataset_path โ€“ a dataset file or a dataset directory

  • suffixes โ€“ files with specified suffixes to be processed

  • kwargs โ€“ extra args

class data_juicer.format.LocalFormatter(dataset_path: str, type: str, suffixes: str | List[str] | None = None, text_keys: List[str] = None, add_suffix=False, **kwargs)[source]#

Bases: BaseFormatter

The class is used to load a dataset from local files or local directory.

__init__(dataset_path: str, type: str, suffixes: str | List[str] | None = None, text_keys: List[str] = None, add_suffix=False, **kwargs)[source]#

Initialization method.

Parameters:
  • dataset_path โ€“ path to a dataset file or a dataset directory

  • type โ€“ a packaged dataset module type (json, csv, etc.)

  • suffixes โ€“ files with specified suffixes to be processed

  • text_keys โ€“ key names of field that stores sample text.

  • add_suffix โ€“ whether to add the file suffix to dataset meta info

  • kwargs โ€“ extra args

load_dataset(num_proc: int = 1, global_cfg=None) Dataset[source]#

Load a dataset from dataset file or dataset directory, and unify its format.

Parameters:
  • num_proc โ€“ number of processes when loading the dataset

  • global_cfg โ€“ global cfg used in consequent processes,

Returns:

formatted dataset

class data_juicer.format.RemoteFormatter(dataset_path: str, text_keys: List[str] = None, **kwargs)[source]#

Bases: BaseFormatter

The class is used to load a dataset from repository of huggingface hub.

__init__(dataset_path: str, text_keys: List[str] = None, **kwargs)[source]#

Initialization method.

Parameters:
  • dataset_path โ€“ a dataset file or a dataset directory

  • text_keys โ€“ key names of field that stores sample text.

  • kwargs โ€“ extra args

load_dataset(num_proc: int = 1, global_cfg=None) Dataset[source]#

Load a dataset from HuggingFace, and unify its format.

Parameters:
  • num_proc โ€“ number of processes when loading the dataset

  • global_cfg โ€“ the global cfg used in consequent processes,

Returns:

formatted dataset

class data_juicer.format.TextFormatter(dataset_path, suffixes=None, add_suffix=False, **kwargs)[source]#

Bases: LocalFormatter

The class is used to load and format text-type files.

e.g. [โ€˜.txtโ€™, โ€˜.pdfโ€™, โ€˜.cppโ€™, โ€˜.docxโ€™]

SUFFIXES = ['.docx', '.pdf', '.txt', '.md', '.tex', '.asm', '.bat', '.cmd', '.c', '.h', '.cs', '.cpp', '.hpp', '.c++', '.h++', '.cc', '.hh', '.C', '.H', '.cmake', '.css', '.dockerfile', '.f90', '.f', '.f03', '.f08', '.f77', '.f95', '.for', '.fpp', '.go', '.hs', '.html', '.java', '.js', '.jl', '.lua', '.markdown', '.php', '.php3', '.php4', '.php5', '.phps', '.phpt', '.pl', '.pm', '.pod', '.perl', '.ps1', '.psd1', '.psm1', '.py', '.rb', '.rs', '.sql', '.scala', '.sh', '.bash', '.command', '.zsh', '.ts', '.tsx', '.vb', 'Dockerfile', 'Makefile', '.xml', '.rst', '.m', '.smali']#
__init__(dataset_path, suffixes=None, add_suffix=False, **kwargs)[source]#

Initialization method.

Parameters:
  • dataset_path โ€“ a dataset file or a dataset directory

  • suffixes โ€“ files with specified suffixes to be processed

  • add_suffix โ€“ Whether to add file suffix to dataset meta info

  • kwargs โ€“ extra args

load_dataset(num_proc: int = 1, global_cfg=None) Dataset[source]#

Load a dataset from local text-type files.

Parameters:
  • num_proc โ€“ number of processes when loading the dataset

  • global_cfg โ€“ the global cfg used in consequent processes,

Returns:

unified_format_dataset.

class data_juicer.format.ParquetFormatter(dataset_path, suffixes=None, **kwargs)[source]#

Bases: LocalFormatter

The class is used to load and format parquet-type files.

Default suffixes is [โ€˜.parquetโ€™]

SUFFIXES = ['.parquet']#
__init__(dataset_path, suffixes=None, **kwargs)[source]#

Initialization method.

Parameters:
  • dataset_path โ€“ a dataset file or a dataset directory

  • suffixes โ€“ files with specified suffixes to be processed

  • kwargs โ€“ extra args

class data_juicer.format.CsvFormatter(dataset_path, suffixes=None, **kwargs)[source]#

Bases: LocalFormatter

The class is used to load and format csv-type files.

Default suffixes is [โ€˜.csvโ€™]

SUFFIXES = ['.csv']#
__init__(dataset_path, suffixes=None, **kwargs)[source]#

Initialization method.

Parameters:
  • dataset_path โ€“ a dataset file or a dataset directory

  • suffixes โ€“ files with specified suffixes to be processed

  • kwargs โ€“ extra args

class data_juicer.format.TsvFormatter(dataset_path, suffixes=None, **kwargs)[source]#

Bases: LocalFormatter

The class is used to load and format tsv-type files.

Default suffixes is [โ€˜.tsvโ€™]

SUFFIXES = ['.tsv']#
__init__(dataset_path, suffixes=None, **kwargs)[source]#

Initialization method.

Parameters:
  • dataset_path โ€“ a dataset file or a dataset directory

  • suffixes โ€“ files with specified suffixes to be processed

  • kwargs โ€“ extra args, e.g. delimiter = โ€˜,โ€™

class data_juicer.format.EmptyFormatter(length, feature_keys: List[str] = [], *args, **kwargs)[source]#

Bases: BaseFormatter

The class is used to create empty data.

SUFFIXES = []#
__init__(length, feature_keys: List[str] = [], *args, **kwargs)[source]#

Initialization method.

Parameters:
  • length โ€“ The empty dataset length.

  • feature_keys โ€“ feature key name list.

load_dataset(*args, **kwargs)[source]#
property null_value#
class data_juicer.format.RayEmptyFormatter(length, feature_keys: List[str] = [], *args, **kwargs)[source]#

Bases: BaseFormatter

The class is used to create empty data for ray.

SUFFIXES = []#
__init__(length, feature_keys: List[str] = [], *args, **kwargs)[source]#

Initialization method.

Parameters:
  • length โ€“ The empty dataset length.

  • feature_keys โ€“ feature key name list.

load_dataset(*args, **kwargs)[source]#
property null_value#