Skip to content

Latest commit

 

History

History
43 lines (27 loc) · 3.46 KB

File metadata and controls

43 lines (27 loc) · 3.46 KB

Data

This script defines a flexible dataset loading and processing framework designed for machine learning models, particularly those dealing with natural language processing (NLP) and potentially vision tasks. The framework is built to work with the JAX library for high-performance machine learning and supports parallel processing and distributed training. Here's an overview of the main components:

DatasetFactory Class

A factory class for creating dataset instances based on configuration parameters. It supports loading datasets from Hugging Face's datasets library (huggingface type), as well as custom JSON-formatted datasets (json and json_vision types). It provides a method to get the default configuration for a dataset, which can be customized with specific parameters.

TextProcessor Class

Processes text data by encoding strings into token IDs using a provided tokenizer. It supports adding special tokens (like BOS and EOS) and can process multiple fields from the data, concatenating them with a specified separator. The default configuration and the processing behavior can be customized.

VisionTextProcessor Class

Designed for processing datasets that include both vision (image or video frames) and text data. It handles encoding of textual data and can integrate special tokens indicating the start and end of vision-related tokens. Supports custom configurations for handling vision data, including specifying the number of tokens per frame and the maximum number of frames.

HuggingfaceDataset Class

Loads and processes datasets from the Hugging Face datasets library. It can stream data, making it efficient for large datasets. The data is processed in chunks, with each chunk transformed into model input and target arrays, along with a loss mask to indicate which tokens should contribute to the loss calculation.

JsonDataset Class

Loads and processes datasets from newline-delimited JSON files, where each line contains a JSON object representing a data example. Supports parallel processing to tokenize and encode the data efficiently across multiple CPU cores. Data examples are batched and padded as necessary to create fixed-size arrays suitable for model training.

JsonVisionDataset Class

Similar to JsonDataset but specifically designed for datasets that include both vision and text data. It can handle special tokens for vision data and supports different modes for padding or not padding the batches.

General Workflow

Configuration: The user specifies the dataset type and configuration parameters, including paths to data files, batch sizes, sequence lengths, and any special tokenization or processing requirements. Dataset Loading: Based on the configuration, the appropriate dataset class is instantiated, which loads the data and prepares it for processing. Data Processing: Text and/or vision data is tokenized and encoded according to the specified processing rules. The data is then batched, with options for padding batches to a fixed size.

Iteration: The dataset objects are iterable, providing batches of data ready for input into a machine learning model. Each batch includes input tokens, target tokens (for supervised learning), and a mask indicating which tokens should be considered for loss calculation. This framework is highly modular and customizable, making it suitable for a wide range of machine learning tasks and models. It leverages JAX's capabilities for efficient computation and is designed with distributed and parallel processing in mind.